예제 #1
0
 public ActionResult Create(FormCollection collection, HttpPostedFileBase ImageFacture)
 {
     try
     {
         Facture facture = new Facture();
         facture.imagefacture       = ImageFacture.FileName;
         facture.descriptionfacture = collection["descriptionfacture"];
         srf = new FactureService();
         srf.Add(facture);
         srf.Commit();
         if (ImageFacture.ContentLength > 0)
         {
             var path = Path.Combine(Server.MapPath("~/Content/uploads/"), ImageFacture.FileName);
             ImageFacture.SaveAs(path);
         }
     }
     catch
     {
         ViewBag.Message = "File upload failed!!";
         return(View());
     }
     return(View());
 }
예제 #2
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 }));
                }
            }
        }