public ActionResult Create(Preference preference)
        {
            if (ModelState.IsValid)
            {
                db.Preference.Add(preference);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(preference);
        }
 public ActionResult Edit(Preference preference, string Categorie, string Remise)
 {
     if (ModelState.IsValid)
     {
         preference.CRecherche = Categorie;
         preference.Remise = Remise;
         db.Entry(preference).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Edit", new { id = preference.Id });
     }
     return View(preference);
 }
Beispiel #3
0
        public ActionResult Insert(short idm, string article)
        {
            try
            {
            int px = article.IndexOf("-") + 2;
            int p = article.Length - px;
            string v = article.Substring(px, p);

            //Create a new instance of the Customer class.
            Liste_produit customer = new Liste_produit
            {
            Id_article = short.Parse(v),
            Id_operation = idm
            };

            Article Art = new Article();
            Mouvement_stock Mv = new Mouvement_stock();

            Art = db.Article.Find(customer.Id_article);
            Mv = db.Mouvement_stock.Find(idm);

            //Perform model binding (fill the customer properties and validate it).
            if (TryUpdateModel(customer))
            {
            if (Mv.Type_mouvement == "Sortie de stock")
            {
                if (Art.Qte_article < customer.Quantite)
                {
                    ModelState.AddModelError("", "La quantité est supérieure à la quantité en stock");
                }
                else
                {
                    //The model is valid - insert the customer and redisplay the grid.
                    customer.Prix_Total = customer.Quantite * customer.Prix;
                    db.Liste_produit.Add(customer);
                    db.SaveChanges();
                    //modiification de la qte d'article
                    Art.Qte_article = Art.Qte_article - customer.Quantite;
                    db.Entry(Art).State = EntityState.Modified;
                    db.SaveChanges();
                    //GridRouteValues() is an extension method which returns the
                    //route values defining the grid state - current page, sort expression, filter etc.
                    return RedirectToAction("Index", new { idm = customer.Id_operation });
                }

            }
            else
            {
                //The model is valid - insert the customer and redisplay the grid.
                customer.Prix_Total = customer.Quantite * customer.Prix;
                db.Liste_produit.Add(customer);
                db.SaveChanges();
                //modiification de la qte d'article
                Art.Qte_article = Art.Qte_article + customer.Quantite;
                db.Entry(Art).State = EntityState.Modified;
                db.SaveChanges();
                //GridRouteValues() is an extension method which returns the
                //route values defining the grid state - current page, sort expression, filter etc.
                return RedirectToAction("Index", new { idm = customer.Id_operation });
            }
            }

            if (customer.Quantite > 0)
            {
            if (Mv.Type_mouvement == "Sortie de stock")
            {
                if (Art.Qte_article < customer.Quantite)
                {
                    ModelState.AddModelError("", "La quantité est supérieure à la quantité en stock");
                }
                else
                {
                    //The model is valid - insert the customer and redisplay the grid.
                    customer.Prix_Total = customer.Quantite * customer.Prix;
                    db.Liste_produit.Add(customer);
                    db.SaveChanges();
                    //modiification de la qte d'article
                    Art.Qte_article = Art.Qte_article - customer.Quantite;
                    db.Entry(Art).State = EntityState.Modified;
                    db.SaveChanges();
                    //GridRouteValues() is an extension method which returns the
                    //route values defining the grid state - current page, sort expression, filter etc.
                    return RedirectToAction("Index", new { idm = customer.Id_operation });
                }

            }
            else
            {
                //The model is valid - insert the customer and redisplay the grid.
                customer.Prix_Total = customer.Quantite * customer.Prix;
                db.Liste_produit.Add(customer);
                db.SaveChanges();
                //modiification de la qte d'article
                Art.Qte_article = Art.Qte_article + customer.Quantite;
                db.Entry(Art).State = EntityState.Modified;
                db.SaveChanges();
                //GridRouteValues() is an extension method which returns the
                //route values defining the grid state - current page, sort expression, filter etc.
                return RedirectToAction("Index", new { idm = customer.Id_operation });
            }
            }
            }
            catch {
            ModelState.AddModelError("", "l'article est incorrect");
            }
              //The model is invalid - render the current view to show any validation errors.
              var articles = db.Article;
              ViewData["articles"] = articles.ToList();

              List<String> listToBind = new List<String>();

              Preference preference = new Preference();
              preference = db.Preference.Find(1);

              if (preference.CRecherche.Trim() == "Code article".Trim())
              {
              foreach (var item in articles.ToList())
              {
              listToBind.Add(item.Code_article + " - " + item.Id_article);
              }
              }
              else
              {
              foreach (var item in articles.ToList())
              {
              listToBind.Add(item.Libelle_article + " - " + item.Id_article);
              }
              }
              ViewData["art"] = listToBind;

              ViewData["op"] = db.Mouvement_stock.Find(idm);

              var liste_produit = from l in db.Liste_produit.Include(l => l.Article).Include(l => l.Mouvement_stock)
                          where l.Id_operation == idm select l ;
              return View("Index", liste_produit.ToList());
        }
        public ActionResult Insert(short id)
        {
            //Create a new instance of the EditableCustomer class.
            Preference client = new Preference();

            //Perform model binding (fill the customer properties and validate it).
            if (TryUpdateModel(client))
            {
                //The model is valid - insert the customer.
                client.Id = id;
                db.Preference.Add(client);
                db.SaveChanges();
            }

            //Rebind the grid
            return View(new GridModel(db.Preference.ToList()));
        }
        public ActionResult Index(string Remise, Boolean TVA = false, short idm = 0)
        {
            if (idm == 0)
                idm = STOCKON.MyGlobalVariables.fvid;
            else
                STOCKON.MyGlobalVariables.fvid = idm;

            var article = db.Article;
            ViewData["articles"] = article.ToList();

            if (!String.IsNullOrEmpty(Remise))

            {
                Facture_vente Fv = new Facture_vente();
                Fv = db.Facture_vente.Find(idm);

                try
                {
                    double R = Convert.ToDouble(Remise);
                    if (db.Preference.Find(1).Remise.Trim() == "Pourcentage".Trim())
                    {
                        if (R > 100)
                            ModelState.AddModelError("", "La remise doit être inférieure à 100");
                        else
                        {
                            Fv.Remise = R;
                            Fv.TVA = TVA;
                            db.Entry(Fv).State = EntityState.Modified;
                            db.SaveChanges();
                        }

                    }
                    else
                    {
                        Fv.Remise = R;
                        Fv.TVA = TVA;
                        db.Entry(Fv).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                }
                catch
                {
                    ModelState.AddModelError("", "La remise doit être un montant positif");
                }
            }

            List<String> listToBind = new List<String>();

            Preference preference = new Preference();
            preference = db.Preference.Find(1);

            if (preference.CRecherche.Trim() == "Code article".Trim())
            {
                foreach (var item in article.ToList())
                {
                    listToBind.Add(item.Code_article + " - " + item.Id_article);
                }
            }
            else
            {
                foreach (var item in article.ToList())
                {
                    listToBind.Add(item.Libelle_article + " - " + item.Id_article);
                }
            }
            ViewData["art"] = listToBind;

            ViewData["Fa"] = db.Facture_vente.Find(idm);

            var liste_produit = from l in db.Liste_produit_vente.Include(l => l.Article).Include(l => l.Facture_vente)
                                where l.Id_facture == idm
                                select l;
            return View(liste_produit.ToList());
        }
Beispiel #6
0
        public ViewResult Insert(short idm)
        {
            //  short id = 1;
             STOCKON.MyGlobalVariables.mid = idm;
            var article = db.Article;
            ViewData["articles"] = article.ToList();

            List<String> listToBind = new List<String>();

            Preference preference = new Preference();
            preference = db.Preference.Find(1);

            if (preference.CRecherche.Trim() == "Code article".Trim())
            {
                foreach (var item in article.ToList())
                {
                    listToBind.Add(item.Code_article + " - " + item.Id_article);
                }
            }
            else
            {
                foreach (var item in article.ToList())
                {
                    listToBind.Add(item.Libelle_article + " - " + item.Id_article);
                }
            }
            ViewData["art"] = listToBind;

            ViewData["op"] = db.Mouvement_stock.Find(idm);

            var liste_produit = from l in db.Liste_produit.Include(l => l.Article).Include(l => l.Mouvement_stock)
                                where l.Id_operation == idm
                                select l;
            return View(liste_produit.ToList());
        }
Beispiel #7
0
        private ModelFacture CreatefactureM(short id)
        {
            ModelFacture modelfacture = new ModelFacture();
            Mouvement_stock Ms = new Mouvement_stock();
            Preference preference = new Preference();

            var facture = from l in db.Mouvement_stock
                          where l.ID_mouvement == id
                          select l;

            var ListeP = from l in db.Liste_produit.Include(l => l.Article)
                         where l.Id_operation == id
                         select l;

            preference = db.Preference.Find(1);

            Ms = facture.ToList().ElementAt(0);

            modelfacture.Num_Facture = Ms.Code_mouvement;
            modelfacture.Type_Op = Ms.Type_mouvement;
            modelfacture.Date_Facture = Ms.Date_mouvement.ToShortDateString();
            modelfacture.Nom_E = preference.Nom;
            modelfacture.Adresse_E = preference.Adresse;
            modelfacture.Numtel_E = preference.Num_telephone;
            modelfacture.Liste_produit = ListeP.ToList();

            return modelfacture;
        }
Beispiel #8
0
        private ModelFacture CreatefactureA(short id)
        {
            ModelFacture modelfacture = new ModelFacture();
            Facture_achat Fa = new Facture_achat();
            Preference preference = new Preference();

            var facture = from l in db.Facture_achat.Include(l => l.Fournisseur)
                          where l.Id_facture == id
                          select l;

            var ListeP = from l in db.Liste_produit_achat.Include(l => l.Article)
                         where l.Id_facture == id
                         select l;

            preference = db.Preference.Find(1);

            Fa = facture.ToList().ElementAt(0);

            if (Fa.Type_facture == "Facture" || Fa.Type_facture == "Facture comptabilisée")
                modelfacture.Type_Op = "Facture de vente";
            else
                modelfacture.Type_Op = Fa.Type_facture;

            modelfacture.Nom_client = Fa.Fournisseur.Nom_fournisseur + " " + Fa.Fournisseur.Prenom_fournisseur;
            modelfacture.Telephone_client = Fa.Fournisseur.Telephone_fournisseur;
            modelfacture.Adresse_client = Fa.Fournisseur.Adresse_fournisseur;
            modelfacture.Num_Facture = Fa.Code_facture;
            modelfacture.Date_Facture = Fa.Date_facture.ToShortDateString();
            modelfacture.Nom_E = preference.Nom;
            modelfacture.Adresse_E = preference.Adresse;
            modelfacture.Numtel_E = preference.Num_telephone;
            modelfacture.Liste_produit_achat = ListeP.ToList();

            return modelfacture;
        }
Beispiel #9
0
        private ModelFacture Createfacture(short id)
        {
            ModelFacture modelfacture = new ModelFacture();
            Facture_vente Fa = new Facture_vente();
            Preference preference = new Preference();

              var facture = from l in db.Facture_vente.Include(l => l.Client)
                                where l.Id_facture == id
                                select l;

              var ListeP = from l in db.Liste_produit_vente.Include(l => l.Article)
                            where l.Id_facture == id
                            select l;

              preference = db.Preference.Find(1);

              Fa = facture.ToList().ElementAt(0);
              if (Fa.Type_facture == "Facture" || Fa.Type_facture == "Facture comptabilisée")
                  modelfacture.Type_Op = "Facture de vente";
              else
                  modelfacture.Type_Op = Fa.Type_facture;

              modelfacture.Remise = (double)Fa.Remise;
              modelfacture.TRemise = preference.Remise;
              modelfacture.TVA = (Boolean)Fa.TVA;
              modelfacture.Nom_client = Fa.Client.Nom_client + " " + Fa.Client.Prenom_client;
              modelfacture.Telephone_client = Fa.Client.Telephone_client;
              modelfacture.Adresse_client = Fa.Client.Adresse_client;
              modelfacture.Num_Facture = Fa.Code_facture;
              modelfacture.Date_Facture = Fa.Date_facture.ToShortDateString();
              modelfacture.Nom_E = preference.Nom;
              modelfacture.Adresse_E = preference.Adresse;
              modelfacture.Numtel_E = preference.Num_telephone;
              modelfacture.Liste_produit_vente = ListeP.ToList();
              modelfacture.TauxTva = (double)preference.Taux_tva;

            return modelfacture;
        }
        public ActionResult Insert(short idm, string article)
        {
            //Create a new instance of the Customer class.
            try
            {
                int px = article.IndexOf("-") + 2;
                int p = article.Length - px;
                string v = article.Substring(px, p);

                Liste_produit_achat customer = new Liste_produit_achat
                {
                    Id_article = short.Parse(v),
                    Id_facture = idm
                };

                Facture_achat Fa = new Facture_achat();
                Fa = db.Facture_achat.Find(idm);

                Article Art = new Article();
                Art = db.Article.Find(customer.Id_article);

                //Perform model binding (fill the customer properties and validate it).
                if (TryUpdateModel(customer))
                {
                    //The model is valid - insert the customer and redisplay the grid.
                    customer.Prix_total = customer.Prix * customer.Quantite;
                    db.Liste_produit_achat.Add(customer);
                    db.SaveChanges();

                    if (Fa.Type_facture.Trim() == "Bon de commande".Trim())
                    { }
                    else
                    {
                        Art.Qte_article = Art.Qte_article + customer.Quantite;
                        db.Entry(Art).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                    //GridRouteValues() is an extension method which returns the
                    //route values defining the grid state - current page, sort expression, filter etc.
                    return RedirectToAction("Index", new { idm = customer.Id_facture });
                }

                if (customer.Quantite > 0)
                {
                    customer.Prix_total = customer.Prix * customer.Quantite;
                    db.Liste_produit_achat.Add(customer);
                    db.SaveChanges();
                    if (Fa.Type_facture.Trim() == "Bon de commande".Trim())
                    { }
                    else
                    {
                        Art.Qte_article = Art.Qte_article + customer.Quantite;
                        db.Entry(Art).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                    return RedirectToAction("Index", new { idm = customer.Id_facture });
                }
                //The model is invalid - render the current view to show any validation errors.
            }
            catch
            {
                ModelState.AddModelError("", "l'article est incorrect");
            }
            var articles = db.Article;
            ViewData["articles"] = articles.ToList();

            List<String> listToBind = new List<String>();

            Preference preference = new Preference();
            preference = db.Preference.Find(1);

            if (preference.CRecherche.Trim() == "Code article".Trim())
            {
                foreach (var item in articles.ToList())
                {
                    listToBind.Add(item.Code_article + " - " + item.Id_article);
                }
            }
            else
            {
                foreach (var item in articles.ToList())
                {
                    listToBind.Add(item.Libelle_article + " - " + item.Id_article);
                }
            }
            ViewData["art"] = listToBind;

            ViewData["Fa"] = db.Facture_achat.Find(idm);

            var liste_produit = from l in db.Liste_produit_achat.Include(l => l.Article).Include(l => l.Facture_achat)
                                where l.Id_facture == idm
                                select l;
            return View("index",liste_produit.ToList());
        }
        public ActionResult Index(short idm = 0)
        {
            if (idm == 0)
                idm = STOCKON.MyGlobalVariables.faid;
            else
                STOCKON.MyGlobalVariables.faid = idm;

            var article = db.Article;
            ViewData["articles"] = article.ToList();

            List<String> listToBind = new List<String>();

            Preference preference = new Preference();
            preference = db.Preference.Find(1);

            if (preference.CRecherche.Trim() == "Code article".Trim())
            {
                foreach (var item in article.ToList())
                {
                    listToBind.Add(item.Code_article + " - " + item.Id_article);
                }
            }
            else
            {
                foreach (var item in article.ToList())
                {
                    listToBind.Add(item.Libelle_article + " - " + item.Id_article);
                }
            }
            ViewData["art"] = listToBind;

            ViewData["Fa"] = db.Facture_achat.Find(idm);

            var liste_produit = from l in db.Liste_produit_achat.Include(l => l.Article).Include(l => l.Facture_achat)
                                where l.Id_facture == idm
                                select l;
            return View(liste_produit.ToList());
        }