public ActionResult CONSULTERFACTURE(String Id)
        {
            using (IDAL dal = new Dal())
            {
                if (dal.VerifierAccesParUtilisateurIdParPrivilegePeut(HttpContext.User.Identity.Name, "CONSULTER_FACTURE"))
                {
                    FactureVM2 FacturetVM = new FactureVM2();

                    FACTURE Facture = dal.ObtenirFactureParId(CRYPTAGE.StringHelpers.Encrypt(Id));

                    if (Facture != null)
                    {
                        FacturetVM = dal.ConvertirFactureFactureVM2(Facture);

                        FacturetVM.Reste = FacturetVM.Montant - dal.SommeTotalePayeeParFacture(Facture);

                        return(View("ConsulterFacture", FacturetVM));
                    }
                    return(RedirectToAction("CONSULTERLISTEFACTURES"));
                }
                else
                {
                    ViewBag.ErrorMessage = dal.getErrorMessageFailedAuthorization();
                    return(View("Error"));
                }
            }
        }
コード例 #2
0
        public ActionResult DeleteAllFactureSelected()
        {
            Guid userSession = new Guid(HttpContext.User.Identity.Name);

            ViewBag.userRole = (new Utilisateurs()).GetUtilisateurRoleToString(userSession);
            try
            {
                bool unique = true;
                if (Session["ListFactureToDelete"] != null)
                {
                    string      hash          = Session["ListFactureToDelete"].ToString();
                    List <Guid> listIdFacture = new List <Guid>();
                    if (!string.IsNullOrEmpty(hash))
                    {
                        if (!hash.Contains(','))
                        {
                            listIdFacture.Add(Guid.Parse(hash));
                        }
                        else
                        {
                            foreach (var id in (hash).Split(','))
                            {
                                listIdFacture.Add(Guid.Parse(id));
                            }
                            unique = false;
                        }
                    }
                    if (listIdFacture.Count != 0)
                    {
                        redactapplicationEntities db = new Models.redactapplicationEntities();
                        foreach (var factureId in listIdFacture)
                        {
                            //suppression des relations
                            //var commandes = db.COMMANDEs.Where(x => x.factureId == factureId);
                            //foreach (var cmde in commandes)
                            //{
                            //    cmde.factureId = null;
                            //    db.SaveChanges();
                            //}
                            //suppression des factures
                            FACTURE facture = db.FACTUREs.SingleOrDefault(x => x.factureId == factureId);
                            db.FACTUREs.Remove(facture);
                        }
                        db.SaveChanges();

                        if (unique)
                        {
                            return(View("DeletedFactureConfirmation"));
                        }
                        return(View("DeletedAllFactureConfirmation"));
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            return(View("ListFacture"));
        }
        public ActionResult GENERERFACTURECONSULTATION(String id)
        {
            using (IDAL dal = new Dal())
            {
                if (dal.VerifierAccesParUtilisateurIdParPrivilegePeut(HttpContext.User.Identity.Name, "GENERER_FACTURE_CONSULTATION"))
                {
                    if (ModelState.IsValid)
                    {
                        FACTURE facture = new FACTURE();

                        facture.Dossier     = dal.ObtenirDossierParId(CRYPTAGE.StringHelpers.Encrypt(id));
                        facture.Utilisateur = dal.ObtenirUtilisateurParId(HttpContext.User.Identity.Name);


                        facture.FactureID = dal.EnregistrerFacture(facture);


                        if (!String.IsNullOrEmpty(facture.FactureID))
                        {
                            FACTURE fact = dal.ObtenirFactureParId(facture.FactureID);
                            PRODUIT prod = dal.ObtenirProduitParId("R15H0520O0701190455P669                     ");

                            if (fact != null && prod != null)
                            {
                                FACTUREDETAILS factureDetails = new FACTUREDETAILS();
                                factureDetails.Facture      = fact;
                                factureDetails.Produit      = prod;
                                factureDetails.Quantite     = 1;
                                factureDetails.PrixUnitaire = prod.PrixVente;
                                dal.EnregistrerFactureDetail(factureDetails);

                                return(RedirectToAction("CONSULTERLISTEFACTURES"));
                            }
                            else
                            {
                                return(View("FormulaireAjoutFacture"));
                            }
                        }
                        else
                        {
                            return(View("FormulaireAjoutFacture"));
                        }
                    }
                    else
                    {
                        return(View("FormulaireAjoutFacture"));
                    }
                }
                else
                {
                    ViewBag.ErrorMessage = dal.getErrorMessageFailedAuthorization();
                    return(View("Error"));
                }
            }
        }
        public ActionResult ENREGISTRERREGLEMENT(String Id)
        {
            using (IDAL dal = new Dal())
            {
                if (dal.VerifierAccesParUtilisateurIdParPrivilegePeut(HttpContext.User.Identity.Name, "ENREGISTRER_REGLEMENT"))
                {
                    CAISSE CaisseOuverte = dal.CaisseOuverteParCaissierId(HttpContext.User.Identity.Name);

                    if (CaisseOuverte != null)
                    {
                        ReglementVM RVM = new ReglementVM();

                        FACTURE fact = dal.ObtenirFactureParId(CRYPTAGE.StringHelpers.Encrypt(Id));
                        if (fact != null)
                        {
                            FactureVM2 FVM = dal.ConvertirFactureFactureVM2(fact);

                            RVM.FactureId        = FVM.Id;
                            RVM.Patient          = FVM.Patient;
                            RVM.ReferenceFacture = FVM.Reference;
                            RVM.Montant          = FVM.Montant;
                            RVM.Reste            = FVM.Montant - dal.SommeTotalePayeeParFacture(fact);
                            RVM.CaisseId         = CaisseOuverte.CaisseID;
                            RVM.Caisse           = CRYPTAGE.StringHelpers.Decrypt(CaisseOuverte.Nom);

                            UTILISATEUR GerantCaisse = dal.ObtenirUtilisateurParId(HttpContext.User.Identity.Name);
                            if (GerantCaisse != null)
                            {
                                RVM.CaissierId = GerantCaisse.UtilisateurID;
                                RVM.Caissier   = CRYPTAGE.StringHelpers.Decrypt(GerantCaisse.Personne.Nom) + " " + CRYPTAGE.StringHelpers.Decrypt(GerantCaisse.Personne.Prenom);
                            }

                            ViewBag.ListeModePaiement = dal.ObtenirTousLesModePaiements();

                            return(View("FormulaireAjoutReglement", RVM));
                        }
                        else
                        {
                            ViewBag.ErrorMessage = "Rassurez-vous que cette facture existe.";
                            return(View("Error"));
                        }
                    }
                    else
                    {
                        ViewBag.ErrorMessage = "Rassurez-vous que votre Caisse est OUVERTE et qu'elle vous a été affectée.";
                        return(View("Error"));
                    }
                }
                else
                {
                    ViewBag.ErrorMessage = dal.getErrorMessageFailedAuthorization();
                    return(View("Error"));
                }
            }
        }
コード例 #5
0
        public ActionResult CreateFacture(FACTUREViewModel model, FormCollection collection)
        {
            if (ModelState.IsValid)
            {
                // Exécute le suivi de session utilisateur
                if (!string.IsNullOrEmpty(Request.QueryString["currentid"]))
                {
                    _userId = Guid.Parse(Request.QueryString["currentid"]);
                    Session["currentid"] = Request.QueryString["currentid"];
                }
                else
                {
                    _userId = Guid.Parse(HttpContext.User.Identity.Name);
                }

                var selectedRedacteurId = model.listRedacteurId;
                var newFacture          = new FACTURE();
                newFacture.dateDebut    = model.dateDebut;
                newFacture.dateFin      = model.dateFin;
                newFacture.dateEmission = DateTime.Now;
                var commandesFacturer = db.COMMANDEs.Where(x => x.date_livraison >= model.dateDebut &&
                                                           x.date_livraison <= model.dateFin &&
                                                           (x.STATUT_COMMANDE != null &&
                                                            (x.STATUT_COMMANDE.statut_cmde.Contains("Validé") || x.STATUT_COMMANDE.statut_cmde.Contains("Refusé"))) &&
                                                           x.factureId == null
                                                           ).ToList();
                if (commandesFacturer.Count() > 0)
                {
                    var redacteur = db.UTILISATEURs.SingleOrDefault(x => x.userId == model.listRedacteurId);

                    double montant   = 0;
                    Guid   factureId = Guid.NewGuid();


                    foreach (var commande in commandesFacturer)
                    {
                        if (commande.STATUT_COMMANDE.statut_cmde.Contains("Validé"))
                        {
                            montant += Convert.ToDouble(commande.nombre_mots) * (Convert.ToDouble(redacteur.redactTarif));
                        }

                        commande.factureId             = factureId;
                        commande.REDACTEUR.redactTarif = String.Format("{0:N0}", commande.REDACTEUR.redactTarif);
                    }

                    newFacture.montant     = String.Format("{0:N0}", montant);
                    newFacture.etat        = false;
                    newFacture.redacteurId = model.listRedacteurId;
                    newFacture.createurId  = _userId;
                    newFacture.factureId   = factureId;
                    int maxRef = (db.FACTUREs.ToList().Count != 0) ? db.FACTUREs.Max(u => u.factureNumero) : 0;
                    newFacture.factureNumero = maxRef + 1;
                    db.FACTUREs.Add(newFacture);

                    int res = db.SaveChanges();
                    if (res > 0)
                    {
                        foreach (var commande in commandesFacturer)
                        {
                            var status = db.STATUT_COMMANDE.SingleOrDefault(s => s.statut_cmde.Contains("Facturé"));
                            commande.STATUT_COMMANDE = status;
                            db.SaveChanges();
                        }
                        return(RedirectToAction("ListFacture"));
                    }
                }
                else
                {
                    ViewBag.ErrorMessage = true;
                    FACTUREViewModel factureVm = SetFactureViewModel();
                    return(View("Create", factureVm));
                }
            }

            return(View("ErrorException"));
        }
        public ActionResult ENREGISTRERREGLEMENT(ReglementVM PVM)
        {
            using (IDAL dal = new Dal())
            {
                if (dal.VerifierAccesParUtilisateurIdParPrivilegePeut(HttpContext.User.Identity.Name, "ENREGISTRER_REGLEMENT"))
                {
                    if (ModelState.IsValid)
                    {
                        REGLEMENT    Reglement    = new REGLEMENT();
                        FACTURE      Facture      = new FACTURE();
                        CAISSE       Caisse       = new CAISSE();
                        MODEPAIEMENT ModePaiement = new MODEPAIEMENT();

                        Caisse = dal.ObtenirCaisseParId(PVM.CaisseId);
                        if (Caisse != null)
                        {
                            Reglement.Caisse = Caisse;
                        }
                        else
                        {
                            ViewBag.ErrorMessage = "Un problème lors de la selection de la Caisse";
                            return(View("Error"));
                        }

                        Facture = dal.ObtenirFactureParId(PVM.FactureId);
                        if (Facture != null)
                        {
                            if (!Facture.EstPaye)
                            {
                                Reglement.Facture = Facture;
                            }
                            else
                            {
                                ViewBag.ErrorMessage = "Cette Facture semble deja etre payée";
                                return(View("Error"));
                            }
                        }
                        else
                        {
                            ViewBag.ErrorMessage = "Un problème lors de la selection de la Facture";
                            return(View("Error"));
                        }



                        ModePaiement = dal.ObtenirModePaiementParId(PVM.ModePaiementId);
                        if (ModePaiement != null)
                        {
                            Reglement.ModePaiement = ModePaiement;
                        }
                        else
                        {
                            ViewBag.ErrorMessage = "Séléctionnez un mode de Paiement valide";
                            return(View("Error"));
                        }

                        List <REGLEMENT> ListePaiements = dal.ObtenirReglementParFactureId(Facture.FactureID);

                        decimal MontantGlobalRecu = 0;
                        foreach (var reg in ListePaiements)
                        {
                            MontantGlobalRecu += reg.MontantRecu;
                        }

                        MontantGlobalRecu += PVM.MontantRecu;

                        Reglement.MontantNet        = PVM.Montant;
                        Reglement.MontantRecu       = PVM.MontantRecu;
                        Reglement.MontantRembourse  = PVM.MontantRembourse;
                        Reglement.MontantARembourse = PVM.MontantARembourse2;
                        Reglement.MontantRestant    = PVM.Reste2;


                        Reglement.ReglementID = dal.EnregistrerReglement(Reglement);

                        if (MontantGlobalRecu >= Reglement.MontantNet)
                        {
                            if (Reglement.ReglementID != null)
                            {
                                dal.MettreAJourFactureReglee(Reglement);
                                return(RedirectToAction("CONSULTERLISTEREGLEMENTS"));
                            }
                            else
                            {
                                ViewBag.ErrorMessage = "Il y a eu un souci lors de l'enregistrement de ce Paiement. Verifiez SVP.";
                                return(View("Error"));
                            }
                        }

                        if (Reglement.ReglementID != null)
                        {
                            CAISSEMOUVEMENT CaisseMvt = new CAISSEMOUVEMENT();
                            CaisseMvt.Caisse      = Reglement.Caisse;
                            CaisseMvt.Montant     = PVM.MontantRecu;
                            CaisseMvt.Raison      = "ENCAISSEMENT";
                            CaisseMvt.Direction   = "IN";
                            CaisseMvt.Commentaire = "Paiement Facture Réf : " + Facture.Reference;

                            dal.EnregistrerCaisseMouvements(CaisseMvt);
                        }

                        return(RedirectToAction("CONSULTERFACTURE", new { id = CRYPTAGE.StringHelpers.Decrypt(Facture.FactureID) }));
                    }
                    else
                    {
                        ViewBag.ErrorMessage = "Formulaire Semble etre mal Renseigné";
                        return(View("Error"));
                    }
                }
                else
                {
                    ViewBag.ErrorMessage = dal.getErrorMessageFailedAuthorization();
                    return(View("Error"));
                }
            }
        }
        public ActionResult ENREGISTRERFACTURE(FactureVM2 factureVM, String[] IdsProduitsSelectionnes, String[] QtesProduitsSelectionnes)
        {
            using (IDAL dal = new Dal())
            {
                if (dal.VerifierAccesParUtilisateurIdParPrivilegePeut(HttpContext.User.Identity.Name, "ENREGISTRER_FACTURE"))
                {
                    if (ModelState.IsValid)
                    {
                        FACTURE facture = new FACTURE();

                        facture.Dossier     = dal.ObtenirDossierParId(CRYPTAGE.StringHelpers.Encrypt(factureVM.DossierID));
                        facture.Utilisateur = dal.ObtenirUtilisateurParId(CRYPTAGE.StringHelpers.Encrypt(factureVM.CaissierID));

                        facture.FactureID = dal.EnregistrerFacture(facture);


                        if (!String.IsNullOrEmpty(facture.FactureID) && IdsProduitsSelectionnes != null && QtesProduitsSelectionnes != null)
                        {
                            FACTURE        fact = dal.ObtenirFactureParId(facture.FactureID);
                            FACTUREDETAILS factureDetails;

                            int i        = 0;
                            int Quantite = 0;
                            foreach (var idProduit in IdsProduitsSelectionnes)
                            {
                                if (!String.IsNullOrEmpty(idProduit) && !String.IsNullOrEmpty(QtesProduitsSelectionnes[i]))
                                {
                                    if (idProduit != "false" && QtesProduitsSelectionnes[i] != "false")
                                    {
                                        factureDetails = new FACTUREDETAILS();

                                        factureDetails.Facture = fact;

                                        PRODUIT Prod = dal.ObtenirProduitParId(idProduit);
                                        factureDetails.Produit      = Prod;
                                        factureDetails.PrixUnitaire = Prod.PrixVente;

                                        Boolean IsConverted = int.TryParse(QtesProduitsSelectionnes[i], out Quantite);

                                        if (IsConverted)
                                        {
                                            factureDetails.Quantite = Quantite;
                                            dal.EnregistrerFactureDetail(factureDetails);
                                        }
                                    }
                                }
                                i += 1;
                            }
                        }

                        return(RedirectToAction("CONSULTERLISTEFACTURES"));
                    }
                    else
                    {
                        return(View("FormulaireAjoutFacture"));
                    }
                }
                else
                {
                    ViewBag.ErrorMessage = dal.getErrorMessageFailedAuthorization();
                    return(View("Error"));
                }
            }
        }
コード例 #8
0
        public ActionResult RECHERCHERPAIEMENT(SearchReglementVM SearchRVM)
        {
            using (IDAL dal = new Dal())
            {
                if (dal.VerifierAccesParUtilisateurIdParPrivilegePeut(HttpContext.User.Identity.Name, "RECHERCHER_PAIEMENT"))
                {
                    List <ReglementVM4> resultatRecherche   = new List <ReglementVM4>();
                    List <DOSSIER>      tempListeDossiers   = new List <DOSSIER>();
                    List <FACTURE>      tempListeFactures   = new List <FACTURE>();
                    List <REGLEMENT>    tempListeReglements = new List <REGLEMENT>();

                    if (!String.IsNullOrEmpty(SearchRVM.CodeDossierPatient))
                    {
                        tempListeDossiers = dal.ObtenirListeDossierParCode(dal.NettoyerChaine(SearchRVM.CodeDossierPatient));

                        foreach (var dossier in tempListeDossiers)
                        {
                            if (dossier != null)
                            {
                                tempListeFactures = dal.ObtenirFactureParDossierId(dossier.DossierID);

                                foreach (var facture in tempListeFactures)
                                {
                                    if (facture != null)
                                    {
                                        FACTURE f = dal.ObtenirFactureParId(facture.FactureID);

                                        if (f != null)
                                        {
                                            if (!String.IsNullOrEmpty(SearchRVM.ReferenceFacture))
                                            {
                                                if (f.Reference == SearchRVM.ReferenceFacture)
                                                {
                                                    tempListeReglements = dal.ObtenirTousLesReglementsParFactureId(f.FactureID);
                                                    break;
                                                }
                                            }
                                            else
                                            {
                                                tempListeReglements = dal.ObtenirTousLesReglementsParFactureId(f.FactureID);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else if (!String.IsNullOrEmpty(SearchRVM.ReferenceFacture))
                    {
                        FACTURE f = dal.ObtenirFactureParReference(CRYPTAGE.StringHelpers.Encrypt(dal.NettoyerChaine(SearchRVM.ReferenceFacture)));

                        if (f != null)
                        {
                            if (!String.IsNullOrEmpty(SearchRVM.ReferencePaiement))
                            {
                                List <REGLEMENT> ListeReglements = dal.ObtenirReglementParFactureId(f.FactureID);

                                foreach (var reg in ListeReglements)
                                {
                                    if (reg != null)
                                    {
                                        tempListeReglements.Add(reg);
                                    }
                                }
                            }
                            else
                            {
                                tempListeReglements = dal.ObtenirTousLesReglementsParFactureId(f.FactureID);
                            }
                        }
                    }
                    else if (!String.IsNullOrEmpty(SearchRVM.ReferencePaiement))
                    {
                        REGLEMENT reg = dal.ObtenirReglementParReference(CRYPTAGE.StringHelpers.Encrypt(dal.NettoyerChaine(SearchRVM.ReferencePaiement)));

                        if (reg != null)
                        {
                            tempListeReglements.Add(reg);
                        }
                    }

                    if (tempListeReglements.Count > 0)
                    {
                        foreach (var reg in tempListeReglements)
                        {
                            if (reg != null)
                            {
                                resultatRecherche.Add(dal.ConvertirReglementReglementVM4(reg));
                            }
                        }
                    }

                    return(PartialView("PartialViewSearchPaiementProduit", resultatRecherche.Distinct().OrderBy(r => r.DateCreation)));
                }
                else
                {
                    ViewBag.ErrorMessage = dal.getErrorMessageFailedAuthorization();
                    return(View("Error"));
                }
            }
        }