public ActionResult Annuler(int idSortie, int?idAdherent, int?idAssociation, int?idHistoriquePaiement)
        {
            Sortie sortie = db.Sorties.Find(idSortie);

            if (sortie.CapaciteActuelle > 0)
            {
                sortie.CapaciteActuelle--;
            }

            Adherent adherent = db.Adherents.Find(idAdherent);

            SortieAdherent sortieAdherent = db.SortieAdherents.Find(idSortie, idAdherent, idAssociation);

            if (sortieAdherent != null)
            {
                db.SortieAdherents.Remove(sortieAdherent);
            }

            HistoriquePaiement historiquePaiement = db.HistoriquePaiements.Where(a => a.IdAdherent == adherent.IdAdherent && a.IdSortie == idSortie).SingleOrDefault();

            if (historiquePaiement != null)
            {
                db.HistoriquePaiements.Remove(historiquePaiement);
                adherent.Solde += sortie.Prix;
            }

            db.SaveChanges();
            return(RedirectToAction("Details/" + idSortie));
        }
Beispiel #2
0
        public ActionResult DeleteConfirmed(int id)
        {
            HistoriquePaiement historiquePaiement = db.HistoriquePaiements.Find(id);

            db.HistoriquePaiements.Remove(historiquePaiement);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        //GET
        public ActionResult Inscription(int?idSortie, int?idAdherent)
        {
            Adherent adherent = db.Adherents.Find(idAdherent);

            //Sécurité
            if (adherent == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            //Instanciation de la sortie à laquelle on souhaite s'inscrire
            Sortie maSortie = db.Sorties.Find(idSortie);

            if (adherent.Solde < maSortie.Prix)
            {
                TempData["Modal"] = 1;
            }
            else if (maSortie.NbInscrits >= maSortie.CapaciteMaximum)
            {
                TempData["Modal"] = 2;
            }
            else
            {
                //Sécurité
                if (maSortie == null)
                {
                    return(HttpNotFound());
                }

                adherent.Solde     -= maSortie.Prix;
                Session["Adherent"] = adherent;

                maSortie.NbInscrits++;

                //Instanciation d'un objet vierge de type sortie adhérent, dont on renseigne les valeurs pour ses différents champs
                SortieAdherent sortieAdherent = new SortieAdherent();
                sortieAdherent.IdAdherent    = adherent.IdAdherent;
                sortieAdherent.IdSortie      = (int)idSortie;
                sortieAdherent.IdAssociation = adherent.IdAssociation;
                sortieAdherent.Statut        = true;

                db.SortieAdherents.Add(sortieAdherent);
                db.SaveChanges();

                //Même chose qu'au dessous, sauf que c'est pour l'historique de paiement
                HistoriquePaiement historiquePaiement = new HistoriquePaiement();
                historiquePaiement.IdAdherent    = adherent.IdAdherent;
                historiquePaiement.IdAssociation = adherent.IdAssociation;
                historiquePaiement.Paiement      = maSortie.Prix;
                historiquePaiement.Date          = DateTime.Now;
                historiquePaiement.IdSortie      = (int)idSortie;

                //Sauvegarde en base de données
                db.HistoriquePaiements.Add(historiquePaiement);
                db.SaveChanges();
            }
            return(RedirectToAction("Index"));
        }
Beispiel #4
0
 public ActionResult Edit([Bind(Include = "IdHistoriquePaiement,IdAdherent,IdAssociation,Paiement,Date,IdSortie")] HistoriquePaiement historiquePaiement)
 {
     if (ModelState.IsValid)
     {
         db.Entry(historiquePaiement).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.IdAdherent    = new SelectList(db.Adherents, "IdAdherent", "Matricule", historiquePaiement.IdAdherent);
     ViewBag.IdAssociation = new SelectList(db.Associations, "IdAssociation", "Nom", historiquePaiement.IdAssociation);
     ViewBag.IdSortie      = new SelectList(db.Sorties, "IdSortie", "Nom", historiquePaiement.IdSortie);
     return(View(historiquePaiement));
 }
Beispiel #5
0
        // GET: HistoriquePaiements/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            HistoriquePaiement historiquePaiement = db.HistoriquePaiements.Find(id);

            if (historiquePaiement == null)
            {
                return(HttpNotFound());
            }
            return(View(historiquePaiement));
        }
Beispiel #6
0
        // GET: HistoriquePaiements/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            HistoriquePaiement historiquePaiement = db.HistoriquePaiements.Find(id);

            if (historiquePaiement == null)
            {
                return(HttpNotFound());
            }
            ViewBag.IdAdherent    = new SelectList(db.Adherents, "IdAdherent", "Matricule", historiquePaiement.IdAdherent);
            ViewBag.IdAssociation = new SelectList(db.Associations, "IdAssociation", "Nom", historiquePaiement.IdAssociation);
            ViewBag.IdSortie      = new SelectList(db.Sorties, "IdSortie", "Nom", historiquePaiement.IdSortie);
            return(View(historiquePaiement));
        }
        public ActionResult Participer(int idSortie, int?idAdherent, int?idAssociation, int?idHistoriquePaiement)
        {
            Sortie sortie = db.Sorties.Find(idSortie);

            if (sortie.CapaciteActuelle != sortie.CapaciteMaximum)
            {
                sortie.CapaciteActuelle++;
            }

            Adherent adherent = db.Adherents.Find(idAdherent);

            adherent.Solde -= sortie.Prix;

            SortieAdherent existSortieAdherent = db.SortieAdherents.Find(idSortie, idAdherent, idAssociation);

            if (existSortieAdherent == null)
            {
                SortieAdherent sortieAdherent = new SortieAdherent();
                sortieAdherent.IdAssociation = adherent.Association.IdAssociation;
                sortieAdherent.IdAdherent    = adherent.IdAdherent;
                sortieAdherent.IdSortie      = sortie.IdSortie;
                db.SortieAdherents.Add(sortieAdherent);
            }

            HistoriquePaiement existePaiement = db.HistoriquePaiements.Where(a => a.IdAdherent == adherent.IdAdherent && a.IdSortie == idSortie).SingleOrDefault();

            if (existePaiement == null)
            {
                HistoriquePaiement historiquePaiement = new HistoriquePaiement();
                historiquePaiement.Adherent    = adherent;
                historiquePaiement.Association = adherent.Association;
                historiquePaiement.Paiement    = sortie.Prix;
                historiquePaiement.Date        = DateTime.Now;
                historiquePaiement.IdSortie    = idSortie;
                db.HistoriquePaiements.Add(historiquePaiement);
            }

            db.SaveChanges();
            return(RedirectToAction("Details/" + idSortie));
        }
        //GET
        public ActionResult CancelInscription(int?idSortie, int?idAdherent, int?idAssociation, int?idHistoriquePaiement)
        {
            Adherent adherent = db.Adherents.Find(idAdherent);

            //Sécurité
            if (adherent == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            Sortie maSortie = db.Sorties.Find(idSortie);

            adherent.Solde     += maSortie.Prix;
            Session["Adherent"] = adherent;

            maSortie.NbInscrits--;


            //Sécurité
            if (maSortie == null)
            {
                return(HttpNotFound());
            }

            //Instanciation de la sortie à laquelle on souhaite annuler son incription,  via les 3 paramètres de notre table sortieAdhérent, et suppression de l'incription
            SortieAdherent sortieAdherent = db.SortieAdherents.Find(idSortie, idAdherent, idAssociation);

            db.SortieAdherents.Remove(sortieAdherent);


            //Recherche de l'historique paiement lié à la sortie via l'idSortie, afin de le delete
            HistoriquePaiement historiquePaiement = db.HistoriquePaiements.FirstOrDefault(hp => hp.IdSortie == maSortie.IdSortie);

            historiquePaiement.Statut = false;

            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #9
0
    public GestionPDF(Client client, long noVendeur, decimal coutLivraison, short typeLivraison, decimal montantTotAvantTaxes, decimal tps, decimal tvq, decimal poidsTotal, int noAut, decimal fraisMarchand)
    {
        detailsCommande            = new List <DetailsCommandes>();
        articleEnPaniersASupprimer = new List <ArticleEnPanier>();

        this.client = client;

        // Ajouter la commande
        vendeur = db.vendeurs.Values.Find(x => x.NoVendeur == noVendeur);

        commande = new Commande(null)
        {
            NoCommande           = db.commandes.NextID(),
            NoClient             = client.NoClient,
            NoVendeur            = noVendeur,
            DateCommande         = DateTime.Now,
            CoutLivraison        = coutLivraison,
            TypeLivraison        = typeLivraison,
            MontantTotAvantTaxes = montantTotAvantTaxes,
            TPS            = tps,
            TVQ            = tvq,
            PoidsTotal     = poidsTotal,
            Statut         = "0",
            NoAutorisation = noAut.ToString()
        };

        // Ajouter à l'historique de paiements
        historique = new HistoriquePaiement(null)
        {
            NoHistorique = db.historiquePaiements.NextID(),
            MontantVenteAvantLivraison = montantTotAvantTaxes,
            NoVendeur      = noVendeur,
            NoClient       = client.NoClient,
            NoCommande     = commande.NoCommande,
            DateVente      = DateTime.Now,
            NoAutorisation = noAut.ToString(),
            FraisLesi      = fraisMarchand,
            Redevance      = (montantTotAvantTaxes + coutLivraison + tps + tvq) * (vendeur.Pourcentage / 100),
            FraisLivraison = coutLivraison,
            FraisTPS       = tps,
            FraisTVQ       = tvq
        };

        // Supprimer les articles dans le panier et les ajouter au détail de la commande
        articleEnPaniersASupprimer = db.articlesEnPanier.Values
                                     .Where(x => x.NoClient == client.NoClient &&
                                            x.NoVendeur == vendeur.NoVendeur).ToList();

        long nextIdDetailCommandes = db.detailsCommandes.NextID();

        foreach (ArticleEnPanier article in articleEnPaniersASupprimer)
        {
            // Produit correspondant à l'article
            Produit produit = db.produits.Values.Find(x => x.NoProduit == article.NoProduit);

            decimal prixArticle = 0;
            if ((produit.PrixVente.HasValue && produit.PrixVente != produit.PrixDemande) &&
                (!produit.DateVente.HasValue || produit.DateVente.Value > DateTime.Now))
            {
                prixArticle = produit.PrixVente.Value;
            }
            else
            {
                prixArticle = produit.PrixDemande.Value;
            }

            // Créer nouveau detail de la commande pour le produit
            DetailsCommandes detail = new DetailsCommandes(null)
            {
                NoDetailCommandes = nextIdDetailCommandes,
                NoCommande        = commande.NoCommande,
                NoProduit         = article.NoProduit,
                PrixVente         = prixArticle,
                Quantité          = article.NbItems
            };
            detailsCommande.Add(detail);

            ++nextIdDetailCommandes;

            // Changer le nombre d'items disponibles pour les produits
            produit.NombreItems -= article.NbItems;
            db.produits.NotifyUpdated(produit);
        }
    }