public IEnumerable <SelectListItem> NumLotListForDropDown()
        {
            using (WakilRecouvContext WakilContext = new WakilRecouvContext())
            {
                using (UnitOfWork UOW = new UnitOfWork(WakilContext))
                {
                    LotService LotService = new LotService(UOW);

                    List <Lot>            Lots      = LotService.GetAll().ToList();
                    List <SelectListItem> listItems = new List <SelectListItem>();
                    listItems.Add(new SelectListItem {
                        Text = "Tous les lots", Value = "0"
                    });

                    Lots.DistinctBy(l => l.NumLot).ForEach(l =>
                    {
                        listItems.Add(new SelectListItem {
                            Text = "Lot " + l.NumLot, Value = l.NumLot
                        });
                    });

                    return(listItems);
                }
            }
        }
        public ActionResult mensuelStatTraite(string year, string month)
        {
            using (WakilRecouvContext WakilContext = new WakilRecouvContext())
            {
                using (UnitOfWork UOW = new UnitOfWork(WakilContext))
                {
                    LotService         LotService         = new LotService(UOW);
                    FormulaireService  FormulaireService  = new FormulaireService(UOW);
                    AffectationService AffectationService = new AffectationService(UOW);
                    EmployeService     EmpService         = new EmployeService(UOW);

                    int mensuelPoste1Tot = 0;
                    int mensuelPoste2Tot = 0;
                    int mensuelPoste3Tot = 0;
                    int mensuelPoste4Tot = 0;
                    int tot = 0;

                    double mensuelRentaPoste1Tot = 0;
                    double mensuelRentaPoste2Tot = 0;
                    double mensuelRentaPoste3Tot = 0;
                    double mensuelRentaPoste4Tot = 0;
                    double totRenta = 0;
                    List <ClientAffecteViewModel> JoinedList = new List <ClientAffecteViewModel>();

                    JoinedList = (from f in FormulaireService.GetAll()
                                  join a in AffectationService.GetAll() on f.AffectationId equals a.AffectationId
                                  join l in LotService.GetAll() on a.LotId equals l.LotId

                                  select new ClientAffecteViewModel
                    {
                        Formulaire = f,
                        Affectation = a,
                        Lot = l,
                    }).ToList();



                    if (month != "" && year != "" && month != null && year != null)
                    {
                        mensuelPoste1Tot = JoinedList.Where(j => j.Affectation.Employe.Username == "POSTE1" && j.Formulaire.TraiteLe.Date.Year + "" == year && j.Formulaire.TraiteLe.Date.Month + "" == month).Count();
                        mensuelPoste2Tot = JoinedList.Where(j => j.Affectation.Employe.Username == "POSTE2" && j.Formulaire.TraiteLe.Date.Year + "" == year && j.Formulaire.TraiteLe.Date.Month + "" == month).Count();
                        mensuelPoste3Tot = JoinedList.Where(j => j.Affectation.Employe.Username == "POSTE3" && j.Formulaire.TraiteLe.Date.Year + "" == year && j.Formulaire.TraiteLe.Date.Month + "" == month).Count();
                        mensuelPoste4Tot = JoinedList.Where(j => j.Affectation.Employe.Username == "POSTE4" && j.Formulaire.TraiteLe.Date.Year + "" == year && j.Formulaire.TraiteLe.Date.Month + "" == month).Count();
                        tot = mensuelPoste1Tot + mensuelPoste2Tot + mensuelPoste3Tot + mensuelPoste4Tot;

                        mensuelRentaPoste1Tot = rentabiliteAgents(year, month, "POSTE1", LotService, FormulaireService, AffectationService);
                        mensuelRentaPoste2Tot = rentabiliteAgents(year, month, "POSTE2", LotService, FormulaireService, AffectationService);
                        mensuelRentaPoste3Tot = rentabiliteAgents(year, month, "POSTE3", LotService, FormulaireService, AffectationService);
                        mensuelRentaPoste4Tot = rentabiliteAgents(year, month, "POSTE4", LotService, FormulaireService, AffectationService);
                        totRenta = mensuelRentaPoste1Tot + mensuelRentaPoste2Tot + mensuelRentaPoste3Tot + mensuelRentaPoste4Tot;
                    }


                    return(Json(new { tot = tot, mensuelPoste1Tot = mensuelPoste1Tot, mensuelPoste2Tot = mensuelPoste2Tot, mensuelPoste3Tot = mensuelPoste3Tot, mensuelPoste4Tot = mensuelPoste4Tot, totRenta = String.Format("{0:0.00}", totRenta), mensuelRentaPoste1Tot = mensuelRentaPoste1Tot, mensuelRentaPoste2Tot = mensuelRentaPoste2Tot, mensuelRentaPoste3Tot = mensuelRentaPoste3Tot, mensuelRentaPoste4Tot = mensuelRentaPoste4Tot }));
                }
            }
        }
        public double rentabiliteAgents(DateTime date, string agent, LotService LotService, FormulaireService FormulaireService, AffectationService AffectationService)
        {
            List <ClientAffecteViewModel> JoinedList     = new List <ClientAffecteViewModel>();
            List <ClientAffecteViewModel> TempJoinedList = new List <ClientAffecteViewModel>();

            double trancheTot = 0;
            double soldeTot   = 0;
            double res        = 0;

            JoinedList = (from f in FormulaireService.GetAll()
                          join a in AffectationService.GetAll() on f.AffectationId equals a.AffectationId
                          join l in LotService.GetAll() on a.LotId equals l.LotId
                          where f.Status == Domain.Entities.Status.VERIFIE
                          select new ClientAffecteViewModel
            {
                Formulaire = f,
                Affectation = a,
                Lot = l,
            }).Where(j => j.Affectation.Employe.Username == agent && j.Formulaire.TraiteLe.Date == date).ToList();



            foreach (ClientAffecteViewModel cvm in JoinedList)
            {
                if (cvm.Formulaire.EtatClient == Domain.Entities.Note.SOLDE_TRANCHE)
                {
                    trancheTot += (cvm.Formulaire.MontantVerseDeclare);
                }

                if (cvm.Formulaire.EtatClient == Domain.Entities.Note.SOLDE)
                {
                    TempJoinedList = getTraitHist(cvm.Affectation.AffectationId, FormulaireService, AffectationService, LotService);
                    if (TempJoinedList.Count() == 0)
                    {
                        soldeTot += (cvm.Formulaire.MontantDebInitial);
                    }
                    else
                    {
                        soldeTot += (TempJoinedList.FirstOrDefault().Formulaire.MontantDebMAJ);
                    }
                }
            }

            res = soldeTot + trancheTot;

            return(res);
        }
Exemplo n.º 4
0
        public IEnumerable <SelectListItem> NumLotListForDropDown(LotService LotService)
        {
            List <Lot>            Lots      = LotService.GetAll().ToList();
            List <SelectListItem> listItems = new List <SelectListItem>();

            listItems.Add(new SelectListItem {
                Selected = true, Text = "Tous les lots", Value = "0"
            });

            Lots.DistinctBy(l => l.NumLot).ForEach(l => {
                listItems.Add(new SelectListItem {
                    Text = "Lot " + l.NumLot, Value = l.NumLot
                });
            });

            return(listItems);
        }
        public List <ClientAffecteViewModel> getTraitHist(int idAff, FormulaireService FormulaireService, AffectationService AffectationService, LotService LotService)
        {
            List <ClientAffecteViewModel> JoinedList = new List <ClientAffecteViewModel>();

            JoinedList = (from f in FormulaireService.GetAll()
                          join a in AffectationService.GetAll() on f.AffectationId equals a.AffectationId
                          join l in LotService.GetAll() on a.LotId equals l.LotId
                          where f.Status == Domain.Entities.Status.VERIFIE && f.EtatClient == Domain.Entities.Note.SOLDE_TRANCHE && f.AffectationId == idAff

                          select new ClientAffecteViewModel
            {
                Formulaire = f,
                Affectation = a,
                Lot = l,
            }).OrderByDescending(f => f.Formulaire.TraiteLe).ToList();

            return(JoinedList);
        }
Exemplo n.º 6
0
        public void LotService_GetAll_ReturnsAllLots()
        {
            var expected       = GetTestLotsModels().ToList();
            var mockUnitOfWork = new Mock <IUnitOfWork>();

            mockUnitOfWork.Setup(m => m.LotRepository.FindAllWithDetails()).Returns(GetTestLotsEntities().AsQueryable());
            var lotService = new LotService(mockUnitOfWork.Object, UnitTestHelper.CreateMapperProfile());

            var actual = lotService.GetAll().ToList();

            Assert.AreEqual(expected.Count, actual.Count);
            for (int i = 0; i < expected.Count; i++)
            {
                Assert.AreEqual(expected[i].Id, actual[i].Id);
                Assert.AreEqual(expected[i].SaleType, actual[i].SaleType);
                Assert.AreEqual(expected[i].TurnkeyPrice, actual[i].TurnkeyPrice);
                Assert.AreEqual(expected[i].IsActive, actual[i].IsActive);
            }
        }
        public ActionResult updateLot(int id)
        {
            using (WakilRecouvContext WakilContext = new WakilRecouvContext())
            {
                using (UnitOfWork UOW = new UnitOfWork(WakilContext))
                {
                    LotService         LotService         = new LotService(UOW);
                    AffectationService AffectationService = new AffectationService(UOW);
                    EmployeService     EmpService         = new EmployeService(UOW);


                    ViewData["list"]  = new SelectList(NumLotListForDropDown(), "Value", "Text");
                    ViewData["agent"] = new SelectList(AgentListForDropDown(), "Value", "Text");

                    //Lot lot = LotService.GetById(id);
                    ClientAffecteViewModel cavm = new ClientAffecteViewModel();
                    cavm = (from a in AffectationService.GetAll()
                            join l in LotService.GetAll() on a.LotId equals l.LotId
                            where l.LotId == id
                            select new ClientAffecteViewModel
                    {
                        Affectation = a,
                        Lot = l
                    }).FirstOrDefault();

                    if (cavm == null)
                    {
                        cavm = new ClientAffecteViewModel();
                        Lot lot = LotService.GetById(id);
                        cavm.Lot = lot;
                    }

                    return(View(cavm));
                }
            }
        }
        public ActionResult quotidienStatTraite(string date)
        {
            using (WakilRecouvContext WakilContext = new WakilRecouvContext())
            {
                using (UnitOfWork UOW = new UnitOfWork(WakilContext))
                {
                    LotService         LotService         = new LotService(UOW);
                    FormulaireService  FormulaireService  = new FormulaireService(UOW);
                    AffectationService AffectationService = new AffectationService(UOW);

                    DateTime d = new DateTime();

                    int quotidienPoste1Tot = 0;
                    int quotidienPoste2Tot = 0;
                    int quotidienPoste3Tot = 0;
                    int quotidienPoste4Tot = 0;
                    int tot = 0;

                    double quotidienRentaPoste1Tot = 0;
                    double quotidienRentaPoste2Tot = 0;
                    double quotidienRentaPoste3Tot = 0;
                    double quotidienRentaPoste4Tot = 0;
                    double totRenta = 0;
                    List <ClientAffecteViewModel> JoinedList = new List <ClientAffecteViewModel>();

                    JoinedList = (from f in FormulaireService.GetAll()
                                  join a in AffectationService.GetAll() on f.AffectationId equals a.AffectationId
                                  join l in LotService.GetAll() on a.LotId equals l.LotId

                                  select new ClientAffecteViewModel
                    {
                        Formulaire = f,
                        Affectation = a,
                        Lot = l,
                    }).ToList();

                    if (date != "" && date != null)
                    {
                        if (DateTime.TryParse(date, out d))
                        {
                            quotidienPoste1Tot = JoinedList.Where(j => j.Affectation.Employe.Username == "POSTE1" && j.Formulaire.TraiteLe.Date == d.Date).Count();
                            quotidienPoste2Tot = JoinedList.Where(j => j.Affectation.Employe.Username == "POSTE2" && j.Formulaire.TraiteLe.Date == d.Date).Count();
                            quotidienPoste3Tot = JoinedList.Where(j => j.Affectation.Employe.Username == "POSTE3" && j.Formulaire.TraiteLe.Date == d.Date).Count();
                            quotidienPoste4Tot = JoinedList.Where(j => j.Affectation.Employe.Username == "POSTE4" && j.Formulaire.TraiteLe.Date == d.Date).Count();
                            tot = quotidienPoste1Tot + quotidienPoste2Tot + quotidienPoste3Tot + quotidienPoste4Tot;


                            quotidienRentaPoste1Tot = rentabiliteAgents(d, "POSTE1", LotService, FormulaireService, AffectationService);
                            quotidienRentaPoste2Tot = rentabiliteAgents(d, "POSTE2", LotService, FormulaireService, AffectationService);
                            quotidienRentaPoste3Tot = rentabiliteAgents(d, "POSTE3", LotService, FormulaireService, AffectationService);
                            quotidienRentaPoste4Tot = rentabiliteAgents(d, "POSTE4", LotService, FormulaireService, AffectationService);
                            totRenta = quotidienRentaPoste1Tot + quotidienRentaPoste2Tot + quotidienRentaPoste3Tot + quotidienRentaPoste4Tot;
                        }
                    }



                    return(Json(new { tot = tot, quotidienPoste1Tot = quotidienPoste1Tot, quotidienPoste2Tot = quotidienPoste2Tot, quotidienPoste3Tot = quotidienPoste3Tot, quotidienPoste4Tot = quotidienPoste4Tot, totRenta = String.Format("{0:0.00}", totRenta), quotidienRentaPoste1Tot = quotidienRentaPoste1Tot, quotidienRentaPoste2Tot = quotidienRentaPoste2Tot, quotidienRentaPoste3Tot = quotidienRentaPoste3Tot, quotidienRentaPoste4Tot = quotidienRentaPoste4Tot }));
                }
            }
        }
        public ActionResult StatLot(int numLot, string typeStat, string dateStat, string agent)
        {
            using (WakilRecouvContext WakilContext = new WakilRecouvContext())
            {
                using (UnitOfWork UOW = new UnitOfWork(WakilContext))
                {
                    LotService         LotService         = new LotService(UOW);
                    FormulaireService  FormulaireService  = new FormulaireService(UOW);
                    AffectationService AffectationService = new AffectationService(UOW);
                    EmployeService     EmpService         = new EmployeService(UOW);

                    ViewData["list"]      = new SelectList(NumLotListForDropDown(), "Value", "Text");
                    ViewData["sortOrder"] = new SelectList(TypeStatForDropDown(), "Value", "Text");
                    ViewBag.AgentList     = new SelectList(AgentListForDropDown(), "Value", "Text");

                    int nb        = 0;
                    int rdv       = 0;
                    int fn        = 0;
                    int versement = 0;
                    int encours   = 0;

                    string avgRdv     = 0 + "";
                    string avgVers    = 0 + "";
                    string avgFn      = 0 + "";
                    string avgencours = 0 + "";


                    ViewData["years"] = new SelectList(YearListForDropDown(), "Value", "Text");
                    ViewData["month"] = new SelectList(MonthListForDropDown(), "Value", "Text");

                    List <Affectation>            affectations = new List <Affectation>();
                    List <Lot>                    lots         = new List <Lot>();
                    List <ClientAffecteViewModel> rdvCAVm      = new List <ClientAffecteViewModel>();
                    List <ClientAffecteViewModel> fnCAVm       = new List <ClientAffecteViewModel>();
                    List <ClientAffecteViewModel> versCAVm     = new List <ClientAffecteViewModel>();
                    List <ClientAffecteViewModel> encoursCAVm  = new List <ClientAffecteViewModel>();
                    List <ClientAffecteViewModel> tot          = new List <ClientAffecteViewModel>();

                    if (numLot == 0)
                    {
                        tot = (from a in AffectationService.GetAll()
                               join l in LotService.GetAll() on a.LotId equals l.LotId
                               select new ClientAffecteViewModel
                        {
                            Affectation = a,
                            Lot = l,
                        }).ToList();


                        rdvCAVm = (from f in FormulaireService.GetAll().OrderByDescending(o => o.TraiteLe)
                                   join a in AffectationService.GetAll() on f.AffectationId equals a.AffectationId
                                   join l in LotService.GetAll() on a.LotId equals l.LotId

                                   select new ClientAffecteViewModel
                        {
                            Formulaire = f,
                            Affectation = a,
                            Lot = l,
                        }).DistinctBy(d => d.Formulaire.AffectationId).Where(f => f.Formulaire.EtatClient == Note.RDV).ToList();


                        fnCAVm = (from f in FormulaireService.GetAll().OrderByDescending(o => o.TraiteLe)
                                  join a in AffectationService.GetAll() on f.AffectationId equals a.AffectationId
                                  join l in LotService.GetAll() on a.LotId equals l.LotId

                                  select new ClientAffecteViewModel
                        {
                            Formulaire = f,
                            Affectation = a,
                            Lot = l,
                        }).DistinctBy(d => d.Formulaire.AffectationId).Where(f => f.Formulaire.EtatClient == Note.FAUX_NUM).ToList();


                        versCAVm = (from f in FormulaireService.GetAll().OrderByDescending(o => o.TraiteLe)
                                    join a in AffectationService.GetAll() on f.AffectationId equals a.AffectationId
                                    join l in LotService.GetAll() on a.LotId equals l.LotId

                                    select new ClientAffecteViewModel
                        {
                            Formulaire = f,
                            Affectation = a,
                            Lot = l,
                        }).DistinctBy(d => d.Formulaire.AffectationId).Where(f => f.Formulaire.EtatClient == Note.SOLDE_TRANCHE || f.Formulaire.EtatClient == Note.SOLDE).ToList();


                        encoursCAVm = (from f in FormulaireService.GetAll().OrderByDescending(o => o.TraiteLe)
                                       join a in AffectationService.GetAll() on f.AffectationId equals a.AffectationId
                                       join l in LotService.GetAll() on a.LotId equals l.LotId

                                       select new ClientAffecteViewModel
                        {
                            Formulaire = f,
                            Affectation = a,
                            Lot = l,
                        }).DistinctBy(d => d.Formulaire.AffectationId).Where(f => f.Formulaire.EtatClient == Note.REFUS_PAIEMENT || f.Formulaire.EtatClient == Note.RAPPEL || f.Formulaire.EtatClient == Note.RACCROCHE || f.Formulaire.EtatClient == Note.NRP || f.Formulaire.EtatClient == Note.INJOIGNABLE || f.Formulaire.EtatClient == Note.AUTRE || f.Formulaire.EtatClient == Note.A_VERIFIE).ToList();
                    }
                    else
                    {
                        tot = (from a in AffectationService.GetAll()
                               join l in LotService.GetAll() on a.LotId equals l.LotId
                               where l.NumLot == numLot.ToString()
                               select new ClientAffecteViewModel
                        {
                            Affectation = a,
                            Lot = l,
                        }).ToList();


                        rdvCAVm = (from f in FormulaireService.GetAll().OrderByDescending(o => o.TraiteLe)
                                   join a in AffectationService.GetAll() on f.AffectationId equals a.AffectationId
                                   join l in LotService.GetAll() on a.LotId equals l.LotId
                                   where l.NumLot == numLot + ""

                                   select new ClientAffecteViewModel
                        {
                            Formulaire = f,
                            Affectation = a,
                            Lot = l,
                        }).DistinctBy(d => d.Formulaire.AffectationId).Where(f => f.Formulaire.EtatClient == Note.RDV).ToList();


                        fnCAVm = (from f in FormulaireService.GetAll().OrderByDescending(o => o.TraiteLe)
                                  join a in AffectationService.GetAll() on f.AffectationId equals a.AffectationId
                                  join l in LotService.GetAll() on a.LotId equals l.LotId
                                  where l.NumLot == numLot + ""

                                  select new ClientAffecteViewModel
                        {
                            Formulaire = f,
                            Affectation = a,
                            Lot = l,
                        }).DistinctBy(d => d.Formulaire.AffectationId).Where(f => f.Formulaire.EtatClient == Note.FAUX_NUM).ToList();


                        versCAVm = (from f in FormulaireService.GetAll().OrderByDescending(o => o.TraiteLe)
                                    join a in AffectationService.GetAll() on f.AffectationId equals a.AffectationId
                                    join l in LotService.GetAll() on a.LotId equals l.LotId
                                    where l.NumLot == numLot + ""

                                    select new ClientAffecteViewModel
                        {
                            Formulaire = f,
                            Affectation = a,
                            Lot = l,
                        }).DistinctBy(d => d.Formulaire.AffectationId).Where(f => f.Formulaire.EtatClient == Note.SOLDE_TRANCHE || f.Formulaire.EtatClient == Note.SOLDE).ToList();


                        encoursCAVm = (from f in FormulaireService.GetAll().OrderByDescending(o => o.TraiteLe)
                                       join a in AffectationService.GetAll() on f.AffectationId equals a.AffectationId
                                       join l in LotService.GetAll() on a.LotId equals l.LotId
                                       where l.NumLot == numLot + ""

                                       select new ClientAffecteViewModel
                        {
                            Formulaire = f,
                            Affectation = a,
                            Lot = l,
                        }).DistinctBy(d => d.Formulaire.AffectationId).Where(f => f.Formulaire.EtatClient == Note.REFUS_PAIEMENT || f.Formulaire.EtatClient == Note.RAPPEL || f.Formulaire.EtatClient == Note.RACCROCHE || f.Formulaire.EtatClient == Note.NRP || f.Formulaire.EtatClient == Note.INJOIGNABLE || f.Formulaire.EtatClient == Note.AUTRE || f.Formulaire.EtatClient == Note.A_VERIFIE).ToList();
                    }

                    if (typeStat == "1")
                    {
                        nb        = tot.Count();
                        rdv       = rdvCAVm.Count();
                        fn        = fnCAVm.Count();
                        versement = versCAVm.Count();
                        encours   = encoursCAVm.Count();

                        avgRdv     = String.Format("{0:0.00}", ((float)rdv / (float)nb) * 100);
                        avgFn      = String.Format("{0:0.00}", ((float)fn / (float)nb) * 100);
                        avgVers    = String.Format("{0:0.00}", ((float)versement / (float)nb) * 100);
                        avgencours = String.Format("{0:0.00}", ((float)encours / (float)nb) * 100);
                    }
                    else if (typeStat == "2")
                    {
                        rdv       = rdvCAVm.Where(f => f.Formulaire.TraiteLe.Date == DateTime.Parse(dateStat).Date).Count();
                        fn        = fnCAVm.Where(f => f.Formulaire.TraiteLe.Date == DateTime.Parse(dateStat).Date).Count();
                        versement = versCAVm.Where(f => f.Formulaire.TraiteLe.Date == DateTime.Parse(dateStat).Date).Count();
                        encours   = encoursCAVm.Where(f => f.Formulaire.TraiteLe.Date == DateTime.Parse(dateStat).Date).Count();

                        nb = rdv + fn + versement + encours;

                        avgRdv     = String.Format("{0:0.00}", ((float)rdv / (float)nb) * 100);
                        avgFn      = String.Format("{0:0.00}", ((float)fn / (float)nb) * 100);
                        avgVers    = String.Format("{0:0.00}", ((float)versement / (float)nb) * 100);
                        avgencours = String.Format("{0:0.00}", ((float)encours / (float)nb) * 100);
                    }
                    else if (typeStat == "3")
                    {
                        rdv       = rdvCAVm.Where(a => a.Affectation.EmployeId + "" == agent).Count();
                        fn        = fnCAVm.Where(a => a.Affectation.EmployeId + "" == agent).Count();
                        versement = versCAVm.Where(a => a.Affectation.EmployeId + "" == agent).Count();
                        encours   = encoursCAVm.Where(a => a.Affectation.EmployeId + "" == agent).Count();

                        nb = rdv + fn + versement + encours;

                        avgRdv     = String.Format("{0:0.00}", ((float)rdv / (float)nb) * 100);
                        avgFn      = String.Format("{0:0.00}", ((float)fn / (float)nb) * 100);
                        avgVers    = String.Format("{0:0.00}", ((float)versement / (float)nb) * 100);
                        avgencours = String.Format("{0:0.00}", ((float)encours / (float)nb) * 100);
                    }
                    else if (typeStat == "4")
                    {
                        rdv       = rdvCAVm.Where(a => a.Affectation.EmployeId + "" == agent && a.Formulaire.TraiteLe.Date == DateTime.Parse(dateStat).Date).Count();
                        fn        = fnCAVm.Where(a => a.Affectation.EmployeId + "" == agent && a.Formulaire.TraiteLe.Date == DateTime.Parse(dateStat).Date).Count();
                        versement = versCAVm.Where(a => a.Affectation.EmployeId + "" == agent && a.Formulaire.TraiteLe.Date == DateTime.Parse(dateStat).Date).Count();
                        encours   = encoursCAVm.Where(a => a.Affectation.EmployeId + "" == agent && a.Formulaire.TraiteLe.Date == DateTime.Parse(dateStat).Date).Count();

                        nb = rdv + fn + versement + encours;

                        avgRdv     = String.Format("{0:0.00}", ((float)rdv / (float)nb) * 100);
                        avgFn      = String.Format("{0:0.00}", ((float)fn / (float)nb) * 100);
                        avgVers    = String.Format("{0:0.00}", ((float)versement / (float)nb) * 100);
                        avgencours = String.Format("{0:0.00}", ((float)encours / (float)nb) * 100);
                    }

                    StatLot statLot = new StatLot()
                    {
                        nb         = nb,
                        rdv        = rdv,
                        fn         = fn,
                        versement  = versement,
                        encours    = encours,
                        avgRdv     = avgRdv.Replace(",", "."),
                        avgFn      = avgFn.Replace(",", "."),
                        avgVers    = avgVers.Replace(",", "."),
                        avgencours = avgencours.Replace(",", ".")
                    };

                    return(View("Index", statLot));
                }
            }
        }
Exemplo n.º 10
0
        public ActionResult ConsulterClients(string SearchString, string numLot, string currentFilter, string currentNumLot, string currentPage, string CurrentSort, string sortOrder, int?page)
        {
            using (WakilRecouvContext WakilContext = new WakilRecouvContext())
            {
                using (UnitOfWork UOW = new UnitOfWork(WakilContext))
                {
                    LotService LotService = new LotService(UOW);


                    ViewData["list"]      = new SelectList(NumLotAllListForDropDown(), "Value", "Text");
                    ViewData["sortOrder"] = new SelectList(SortOrdrForDropDown(), "Value", "Text");

                    List <SuiviAffectationViewModel> JoinedList = new List <SuiviAffectationViewModel>();


                    if (sortOrder != null)
                    {
                        //page = 1;
                    }
                    else
                    {
                        sortOrder = CurrentSort;
                    }


                    ViewBag.CurrentSort = sortOrder;


                    if (page == null)
                    {
                        if (currentPage != null)
                        {
                            page = int.Parse(currentPage);
                        }
                    }

                    ViewBag.page = page;

                    if (SearchString != null)
                    {
                        // page = 1;
                    }
                    else
                    {
                        SearchString = currentFilter;
                    }

                    ViewBag.currentFilter = SearchString;

                    if (numLot != null)
                    {
                        //page = 1;
                    }
                    else
                    {
                        numLot = currentNumLot;
                    }

                    ViewBag.currentNumLot = numLot;


                    JoinedList = (from a in LotService.GetAll()

                                  select new SuiviAffectationViewModel
                    {
                        LotId = a.LotId
                        ,
                        Adresse = a.Adresse
                        ,
                        Compte = a.Compte
                        ,
                        DescIndustry = a.DescIndustry
                        ,
                        Emploi = a.Emploi
                        ,
                        IDClient = a.IDClient

                        ,
                        NomClient = a.NomClient
                        ,
                        Numero = a.Numero
                        ,
                        NumLot = a.NumLot
                        ,
                        PostCode = a.PostCode
                        ,
                        SoldeDebiteur = a.SoldeDebiteur
                        ,
                        TelFixe = a.TelFixe
                        ,
                        TelPortable = a.TelPortable
                        ,
                        Type = a.Type
                    }).ToList();

                    if (!String.IsNullOrEmpty(numLot))
                    {
                        if (numLot.Equals("0") == false)
                        {
                            JoinedList = JoinedList.Where(j => j.NumLot.Equals(numLot)).ToList();
                        }
                    }

                    if (!String.IsNullOrEmpty(SearchString))
                    {
                        JoinedList = JoinedList.Where(s => s.Adresse.IfNullOrWhiteSpace("").ToLower().Contains(SearchString.ToLower()) ||
                                                      s.Compte.IfNullOrWhiteSpace("").ToLower().Contains(SearchString.ToLower()) ||
                                                      s.DescIndustry.IfNullOrWhiteSpace("").ToLower().Contains(SearchString.ToLower()) ||
                                                      s.IDClient.IfNullOrWhiteSpace("").ToLower().Contains(SearchString.ToLower()) ||
                                                      s.NomClient.IfNullOrWhiteSpace("").ToLower().Contains(SearchString.ToLower()) ||
                                                      s.Numero.IfNullOrWhiteSpace("").ToLower().Contains(SearchString.ToLower()) ||
                                                      s.SoldeDebiteur.IfNullOrWhiteSpace("").ToLower().Contains(SearchString.ToLower()) ||
                                                      s.TelFixe.IfNullOrWhiteSpace("").ToLower().Contains(SearchString.ToLower()) ||
                                                      s.TelPortable.IfNullOrWhiteSpace("").ToLower().Contains(SearchString.ToLower())

                                                      ).ToList();
                    }


                    switch (sortOrder)
                    {
                    case "0":

                        JoinedList = JoinedList.OrderBy(s => s.NomClient).ToList();

                        break;

                    case "1":

                        JoinedList = JoinedList.OrderByDescending(s => s.SoldeDebiteur).ToList();

                        break;

                    case "2":
                        JoinedList = JoinedList.OrderBy(s => s.SoldeDebiteur).ToList();

                        break;

                    default:


                        break;
                    }

                    ViewBag.total = JoinedList.Count();
                    int pageSize   = 10;
                    int pageNumber = (page ?? 1);
                    return(View(JoinedList.ToPagedList(pageNumber, pageSize)));
                }
            }
        }
Exemplo n.º 11
0
        public ActionResult ExtraireLettreAction(string numLot, string debutDate, string finDate, string agent)
        {
            using (WakilRecouvContext WakilContext = new WakilRecouvContext())
            {
                using (UnitOfWork UOW = new UnitOfWork(WakilContext))
                {
                    FormulaireService  FormulaireService  = new FormulaireService(UOW);
                    AffectationService AffectationService = new AffectationService(UOW);
                    LotService         LotService         = new LotService(UOW);
                    LettreService      lettreService      = new LettreService(UOW);
                    EmployeService     EmployeService     = new EmployeService(UOW);

                    ViewData["list"]  = new SelectList(NumLotListForDropDown(LotService), "Value", "Text");
                    ViewBag.AgentList = new SelectList(AgentListForDropDown(EmployeService), "Value", "Text");

                    string   lettreDir = GetFolderNameForLettre();
                    DateTime startDate = DateTime.Parse(debutDate);
                    DateTime endDate   = DateTime.Parse(finDate);

                    if (!Directory.Exists(lettreDir))
                    {
                        Directory.CreateDirectory(lettreDir);
                    }

                    string lettreDirList = Directory.GetDirectories(lettreDir).Length + 1 + "_" + ((DateTimeOffset)DateTime.UtcNow).ToUnixTimeSeconds() + "";

                    string dirLettre = "";

                    if (!Directory.Exists(lettreDir + "/" + lettreDirList))
                    {
                        Directory.CreateDirectory(lettreDir + "/" + lettreDirList);
                        dirLettre = lettreDir + "/" + lettreDirList;
                    }

                    List <LettreContent> lettreJoinedList = new List <LettreContent>();

                    if (numLot == "0")
                    {
                        lettreJoinedList = (from f in FormulaireService.GetAll()
                                            join a in AffectationService.GetAll() on f.AffectationId equals a.AffectationId
                                            join l in LotService.GetAll() on a.LotId equals l.LotId
                                            where (f.TraiteLe.Date >= startDate.Date && f.TraiteLe.Date <= endDate.Date) && (f.EtatClient == Note.FAUX_NUM || f.EtatClient == Note.NRP || f.EtatClient == Note.INJOIGNABLE) && lettreIsTrue(FormulaireService, a.AffectationId)
                                            select new LettreContent
                        {
                            NumLot = l.NumLot,
                            Adresse = l.Adresse,
                            NomClient = l.NomClient,
                            Agence = l.DescIndustry,
                            Compte = l.Compte
                        }).ToList();

                        if (int.Parse(agent) != 0)
                        {
                            lettreJoinedList = (from f in FormulaireService.GetAll()
                                                join a in AffectationService.GetAll() on f.AffectationId equals a.AffectationId
                                                join l in LotService.GetAll() on a.LotId equals l.LotId
                                                where (f.TraiteLe.Date >= startDate.Date && f.TraiteLe.Date <= endDate.Date) && (f.EtatClient == Note.FAUX_NUM || f.EtatClient == Note.NRP || f.EtatClient == Note.INJOIGNABLE) && lettreIsTrue(FormulaireService, a.AffectationId) && a.EmployeId == int.Parse(agent)
                                                select new LettreContent
                            {
                                NumLot = l.NumLot,
                                Adresse = l.Adresse,
                                NomClient = l.NomClient,
                                Agence = l.DescIndustry,
                                Compte = l.Compte
                            }).ToList();
                        }
                        else
                        {
                            lettreJoinedList = (from f in FormulaireService.GetAll()
                                                join a in AffectationService.GetAll() on f.AffectationId equals a.AffectationId
                                                join l in LotService.GetAll() on a.LotId equals l.LotId
                                                where (f.TraiteLe.Date >= startDate.Date && f.TraiteLe.Date <= endDate.Date) && (f.EtatClient == Note.FAUX_NUM || f.EtatClient == Note.NRP || f.EtatClient == Note.INJOIGNABLE) && lettreIsTrue(FormulaireService, a.AffectationId)
                                                select new LettreContent
                            {
                                NumLot = l.NumLot,
                                Adresse = l.Adresse,
                                NomClient = l.NomClient,
                                Agence = l.DescIndustry,
                                Compte = l.Compte
                            }).ToList();
                        }
                    }
                    else
                    {
                        if (int.Parse(agent) != 0)
                        {
                            lettreJoinedList = (from f in FormulaireService.GetAll()
                                                join a in AffectationService.GetAll() on f.AffectationId equals a.AffectationId
                                                join l in LotService.GetAll() on a.LotId equals l.LotId
                                                where (f.TraiteLe.Date >= startDate.Date && f.TraiteLe.Date <= endDate.Date) && (f.EtatClient == Note.FAUX_NUM || f.EtatClient == Note.NRP || f.EtatClient == Note.INJOIGNABLE) && lettreIsTrue(FormulaireService, a.AffectationId) && (l.NumLot.Equals(numLot)) && a.EmployeId == int.Parse(agent)
                                                select new LettreContent
                            {
                                NumLot = l.NumLot,
                                Adresse = l.Adresse,
                                NomClient = l.NomClient,
                                Agence = l.DescIndustry,
                                Compte = l.Compte,
                                IdAgent = a.EmployeId + ""
                            }).ToList();
                        }
                        else
                        {
                            lettreJoinedList = (from f in FormulaireService.GetAll()
                                                join a in AffectationService.GetAll() on f.AffectationId equals a.AffectationId
                                                join l in LotService.GetAll() on a.LotId equals l.LotId
                                                where (f.TraiteLe.Date >= startDate.Date && f.TraiteLe.Date <= endDate.Date) && (f.EtatClient == Note.FAUX_NUM || f.EtatClient == Note.NRP || f.EtatClient == Note.INJOIGNABLE) && lettreIsTrue(FormulaireService, a.AffectationId) && (l.NumLot.Equals(numLot))
                                                select new LettreContent
                            {
                                NumLot = l.NumLot,
                                Adresse = l.Adresse,
                                NomClient = l.NomClient,
                                Agence = l.DescIndustry,
                                Compte = l.Compte,
                                IdAgent = a.EmployeId + ""
                            }).ToList();
                        }
                    }



                    int x = 0;
                    ViewBag.total = lettreJoinedList.Count();
                    foreach (LettreContent lc in lettreJoinedList)
                    {
                        string path = dirLettre + "/" + x + "_" + "lettre" + "_" + lc.Compte + ".docx";

                        if (Directory.Exists(dirLettre))
                        {
                            GenerateWordForLettre(path, lc);
                        }
                        ViewData["currClient"] = x;
                        x++;
                    }

                    string zipPath = zipFolderResult(dirLettre);

                    string adressExcelPath = Server.MapPath("~/Uploads/Lettre/0_Result/") + DateTime.Now.ToString("dd.MM.yyyy") + "_" + Path.GetFileName(dirLettre) + ".xlsx";

                    GenerateExcelForLettre(GenerateDatatableFromJoinedListForLettre(lettreJoinedList), adressExcelPath);
                    Lettre lettre = new Lettre
                    {
                        DateDeb              = startDate.Date,
                        DateFin              = endDate.Date,
                        DateExtrait          = DateTime.Now,
                        LettrePathName       = zipPath,
                        LettreAdressPathName = Path.GetFileName(adressExcelPath)
                    };

                    lettreService.Add(lettre);
                    lettreService.Commit();

                    return(RedirectToAction("Renseigner", new { page = 1 }));
                }
            }
        }
Exemplo n.º 12
0
        public ActionResult extraireFacture(string numLot, string factureNum, string pourcentage, string debutDate, string finDate)
        {
            using (WakilRecouvContext WakilContext = new WakilRecouvContext())
            {
                using (UnitOfWork UOW = new UnitOfWork(WakilContext))
                {
                    FormulaireService  FormulaireService  = new FormulaireService(UOW);
                    LotService         LotService         = new LotService(UOW);
                    AffectationService AffectationService = new AffectationService(UOW);
                    FactureService     factureService     = new FactureService(UOW);

                    ViewData["list"] = new SelectList(NumLotListForDropDown(LotService), "Value", "Text");

                    DateTime startDate   = DateTime.Parse(debutDate);
                    DateTime endDate     = DateTime.Parse(finDate);
                    double   trancheTot  = 0;
                    double   soldeTot    = 0;
                    double   tot         = 0;
                    float    revenuParOp = float.Parse(pourcentage.Replace(".", ","));
                    List <ClientAffecteViewModel> JoinedList       = new List <ClientAffecteViewModel>();
                    List <ClientAffecteViewModel> TempJoinedList   = new List <ClientAffecteViewModel>();
                    List <ClientAffecteViewModel> AnnexeJoinedList = new List <ClientAffecteViewModel>();

                    if (numLot == "0")
                    {
                        JoinedList = (from f in FormulaireService.GetAll()
                                      join a in AffectationService.GetAll() on f.AffectationId equals a.AffectationId
                                      join l in LotService.GetAll() on a.LotId equals l.LotId
                                      where f.Status == Domain.Entities.Status.VERIFIE
                                      select new ClientAffecteViewModel
                        {
                            Formulaire = f,
                            Affectation = a,
                            Lot = l,
                        }).Where(j => j.Formulaire.TraiteLe.Date >= startDate.Date && j.Formulaire.TraiteLe.Date <= endDate.Date).ToList();
                    }
                    else
                    {
                        JoinedList = (from f in FormulaireService.GetAll()
                                      join a in AffectationService.GetAll() on f.AffectationId equals a.AffectationId
                                      join l in LotService.GetAll() on a.LotId equals l.LotId
                                      where f.Status == Domain.Entities.Status.VERIFIE && l.NumLot.Equals(numLot)
                                      select new ClientAffecteViewModel
                        {
                            Formulaire = f,
                            Affectation = a,
                            Lot = l,
                        }).Where(j => j.Formulaire.TraiteLe.Date >= startDate.Date && j.Formulaire.TraiteLe.Date <= endDate.Date).ToList();
                    }

                    foreach (ClientAffecteViewModel cvm in JoinedList)
                    {
                        if (cvm.Formulaire.EtatClient == Domain.Entities.Note.SOLDE_TRANCHE)
                        {
                            trancheTot  += (cvm.Formulaire.MontantVerseDeclare * revenuParOp) / 100;
                            cvm.vers     = cvm.Formulaire.MontantVerseDeclare;
                            cvm.recouvre = cvm.Formulaire.MontantVerseDeclare;
                            AnnexeJoinedList.Add(cvm);
                        }

                        if (cvm.Formulaire.EtatClient == Domain.Entities.Note.SOLDE)
                        {
                            TempJoinedList = getTraitHist(cvm.Affectation.AffectationId, FormulaireService, AffectationService, LotService);
                            if (TempJoinedList.Count() == 0)
                            {
                                soldeTot    += (cvm.Formulaire.MontantDebInitial * revenuParOp) / 100;
                                cvm.recouvre = cvm.Formulaire.MontantDebInitial;
                                cvm.vers     = cvm.Formulaire.MontantVerseDeclare;

                                AnnexeJoinedList.Add(cvm);
                            }
                            else
                            {
                                soldeTot    += (TempJoinedList.FirstOrDefault().Formulaire.MontantDebMAJ *revenuParOp) / 100;
                                cvm.vers     = cvm.Formulaire.MontantVerseDeclare;
                                cvm.recouvre = TempJoinedList.FirstOrDefault().Formulaire.MontantDebMAJ;
                                AnnexeJoinedList.Add(cvm);
                            }
                        }
                    }

                    string        lotsNames   = "";
                    List <string> listNameLot = JoinedList.DistinctBy(j => j.Lot.NumLot).Select(l => l.Lot.NumLot).ToList();

                    if (listNameLot.Count() == 1)
                    {
                        lotsNames = listNameLot.FirstOrDefault();
                    }
                    else if (listNameLot.Count() > 1)
                    {
                        string lastlots = JoinedList.DistinctBy(j => j.Lot.NumLot).Select(l => l.Lot.NumLot).LastOrDefault();
                        listNameLot.RemoveAt(listNameLot.Count - 1);
                        string lots = String.Join(", ", listNameLot);
                        lotsNames = lots + " et " + lastlots;
                    }


                    tot = soldeTot + trancheTot;
                    FactureContent factureContent = new FactureContent();
                    factureContent.FacNum       = factureNum;
                    factureContent.Date         = DateTime.Today;
                    factureContent.Beneficiere  = "Zitouna Bank";
                    factureContent.PrixHT       = tot;
                    factureContent.PrixTVA      = (tot * 19) / 100;
                    factureContent.TimbreFiscal = 0.600;

                    factureContent.PrixTTC = tot + factureContent.PrixTVA;

                    string  annexeFileName  = "Annexe_" + DateTime.Now.ToString("dd.MM.yyyy") + "_" + ((DateTimeOffset)DateTime.UtcNow).ToUnixTimeSeconds() + ".xlsx";
                    string  factureFileName = "Facture_" + DateTime.Now.ToString("dd.MM.yyyy") + "_" + ((DateTimeOffset)DateTime.UtcNow).ToUnixTimeSeconds() + ".pdf";
                    string  pathAnnexe      = GetFolderName() + "/" + annexeFileName;
                    string  pathFacture     = GetFolderName() + "/" + factureFileName;
                    Facture facture         = new Facture()
                    {
                        AnnexePathName  = annexeFileName,
                        FacturePathName = factureFileName,
                        DateDeb         = startDate,
                        DateFin         = endDate,
                        DateExtrait     = DateTime.Now
                    };
                    factureService.Add(facture);
                    factureService.Commit();
                    GenerateExcel(GenerateDatatableFromJoinedList(AnnexeJoinedList), pathAnnexe, String.Format("{0:0.000}", AnnexeJoinedList.Sum(j => j.recouvre)));
                    GeneratePDF(pathFacture, lotsNames, factureContent);

                    return(RedirectToAction("genererFacture", new { page = 1 }));
                }
            }
        }
Exemplo n.º 13
0
        public ActionResult Index()
        {
            using (WakilRecouvContext WakilContext = new WakilRecouvContext())
            {
                using (UnitOfWork UOW = new UnitOfWork(WakilContext))
                {
                    EmployeService     EmpService         = new EmployeService(UOW);
                    RoleService        RoleService        = new RoleService(UOW);
                    AffectationService AffectationService = new AffectationService(UOW);
                    LotService         LotService         = new LotService(UOW);
                    FormulaireService  FormulaireService  = new FormulaireService(UOW);

                    List <ClientAffecteViewModel> traiteList = new List <ClientAffecteViewModel>();

                    List <HomeViewModel> result = new List <HomeViewModel>();
                    List <Lot>           lots   = new List <Lot>();


                    string[] lotsLst = { };

                    lots    = LotService.GetAll().ToList();
                    lotsLst = lots.DistinctBy(l => l.NumLot).Select(l => l.NumLot).ToArray();

                    List <Affectation> Affectations = new List <Affectation>();
                    List <Formulaire>  Formulaires  = new List <Formulaire>();
                    string[]           agents       = { };

                    Affectations = AffectationService.GetAll().ToList();
                    Formulaires  = FormulaireService.GetAll().OrderByDescending(o => o.TraiteLe).ToList();

                    foreach (string numlot in lotsLst)
                    {
                        lots = LotService.GetAll().Where(l => l.NumLot.Equals(numlot)).ToList();

                        traiteList = (from f in Formulaires
                                      join a in Affectations on f.AffectationId equals a.AffectationId
                                      join l in lots on a.LotId equals l.LotId
                                      select new ClientAffecteViewModel
                        {
                            Formulaire = f,
                            Affectation = a,
                            Lot = l,
                        }).DistinctBy(d => d.Formulaire.AffectationId).ToList();

                        var agentLinq = (from a in Affectations
                                         join l in lots on a.LotId equals l.LotId
                                         select new ClientAffecteViewModel
                        {
                            Affectation = a
                        });


                        agents = agentLinq.DistinctBy(a => a.Affectation.Employe.Username).Select(a => a.Affectation.Employe.Username).ToArray();

                        string agentsStr = string.Join(", ", agents);

                        float  nbAffTotal = agentLinq.Count();
                        float  nbTraite   = traiteList.Count();
                        string avgLot     = String.Format("{0:0.00}", (nbTraite / nbAffTotal) * 100);


                        HomeViewModel homeViewModel = new HomeViewModel
                        {
                            agents     = agentsStr,
                            nbAffTotal = nbAffTotal + "",
                            nbTraite   = nbTraite + "",
                            numLot     = numlot,
                            avancement = avgLot.Replace(",", ".")
                        };
                        result.Add(homeViewModel);
                    }

                    return(View(result));
                }
            }
        }