Ejemplo n.º 1
0
        public ActionResult Create(Facture_vente fac, string Mrg, string TypeF, string test)
        {
            fac.Mode_reglement = Mrg;
            fac.Type_facture = TypeF;
            try
            {
                if (ModelState.IsValid)
                {
                    try
                    {
                        int px = test.IndexOf("-") + 2;
                        int p = test.Length - px;
                        string v = test.Substring(px, p);
                        fac.Id_client = short.Parse(v);
                        fac.Remise = 0;
                        fac.TVA = false;

                        db.Facture_vente.Add(fac);
                        db.SaveChanges();
                        return RedirectToAction("Index", "Liste_produit_vente", new { idm = fac.Id_facture });
                    }
                    catch
                    {
                        ModelState.AddModelError("", "Le client est incorrect");
                    }

                }
               // ViewBag.Id_client = new SelectList(db.Client, "Id_client", "Nom_client");
                var clients = db.Client.ToList();

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

                foreach (var item in clients)
                {
                    listToBind.Add(item.Nom_client + " " + item.Prenom_client + " - " + item.Id_client);
                }

                ViewData["Client"] = listToBind;
                return View();

            }
            catch
            {
               // ViewBag.Id_client = new SelectList(db.Client, "Id_client", "Nom_client");
                var clients = db.Client.ToList();

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

                foreach (var item in clients)
                {
                    listToBind.Add(item.Nom_client + " " + item.Prenom_client + " - " + item.Id_client);
                }

                ViewData["Client"] = listToBind;
                return View();
            }
        }
Ejemplo n.º 2
0
        //
        // GET: /FactureA/Create
        public ActionResult Create()
        {
            //ViewBag.Id_client = new SelectList(db.Client, "Id_client", "Nom_client");
            var clients = db.Client.ToList();
            Facture_vente facture_vente = new Facture_vente();

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

            foreach (var item in clients)
            {
                listToBind.Add(item.Nom_client + " " + item.Prenom_client + " - " + item.Id_client);
            }

            var fa = db.Facture_vente.Max(a => a.Id_facture) + 1;

            facture_vente.Code_facture = MyGlobalVariables.FormatCode("FAV", fa);

            ViewData["Client"] = listToBind;
            return View(facture_vente);
        }
        public ActionResult DeleteP(short id, short idm)
        {
            var liste_produit1 = from l in db.Liste_produit_vente.Include(l => l.Article).Include(l => l.Facture_vente)
                                 where l.Id_facture == idm && l.Id_article == id
                                 select l;

            Liste_produit_vente L = liste_produit1.First();

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

             if (Fa.Type_facture.Trim() == "Bon de commande".Trim())
             {
                    }
                    else
                    {
            L.Article.Qte_article = L.Article.Qte_article + L.Quantite;
            db.Entry(L.Article).State = EntityState.Modified;
            db.SaveChanges();
             }

            db.Liste_produit_vente.Remove(L);
            db.SaveChanges();

            return RedirectToAction("Index", new { idm = idm });

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

             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());*/
        }
        public ActionResult Update(short id, short idm)
        {
            //Create a new instance of the Customer class.
            var liste_produit1 = from l in db.Liste_produit_vente.Include(l => l.Article).Include(l => l.Facture_vente)
                                 where l.Id_facture == idm && l.Id_article == id
                                 select l;
            Facture_vente Fa = new Facture_vente();
            Fa = db.Facture_vente.Find(idm);

            Liste_produit_vente L = liste_produit1.First();
            var QteP = L.Quantite;
            var Prixp = L.Prix;

               // var Art = new Article();

            //Art = db.Article.Find(L.Id_article);
            //Perform model binding (fill the customer properties and validate it).
            //L.Id_article = article;
            if (TryUpdateModel(L))
            {
                if (Fa.Type_facture.Trim() == "Bon de commande".Trim())
                {
                    L.Prix = Prixp;
                    L.Prix_Total = L.Quantite * L.Prix;
                    db.Entry(L).State = EntityState.Modified;
                    db.SaveChanges();
                    return RedirectToAction("Index", new { idm = L.Id_facture });
                }
                else
                {
                    if (L.Article.Qte_article + QteP < L.Quantite)
                    {
                        ModelState.AddModelError("", "La quantité est supérieure à la quantité en stock");
                    }
                    else
                    {
                        if ((L.Article.Qte_article + QteP - L.Quantite) <= L.Article.Stock_critique)
                        {
                            ModelState.AddModelError("", "La quantité en stock pour cet article est en dessous du sueil critique");
                        }

                        L.Prix = Prixp;
                        L.Prix_Total = L.Quantite * L.Prix;
                        db.Entry(L).State = EntityState.Modified;
                        db.SaveChanges();
                        L.Article.Qte_article = (L.Article.Qte_article + QteP - L.Quantite);
                        db.Entry(L.Article).State = EntityState.Modified;
                        db.SaveChanges();

                        /* Art.Qte_article = Art.Qte_article + QteP;
                         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 = L.Id_facture });
                    }
                }
            }

            if (L.Quantite > 0)
            {
                if (Fa.Type_facture.Trim() == "Bon de commande".Trim())
                {
                    L.Prix = Prixp;
                    L.Prix_Total = L.Quantite * L.Prix;
                    db.Entry(L).State = EntityState.Modified;
                    db.SaveChanges();
                    return RedirectToAction("Index", new { idm = L.Id_facture });
                }
                else
                {
                    if (L.Article.Qte_article + QteP < L.Quantite)
                    {
                        ModelState.AddModelError("", "La quantité est supérieure à la quantité en stock");
                    }
                    else
                    {
                        if ((L.Article.Qte_article + QteP - L.Quantite) <= L.Article.Stock_critique)
                        {
                            ModelState.AddModelError("", "La quantité en stock pour cet article est en dessous du sueil critique");
                        }

                        L.Prix_Total = L.Quantite * L.Prix;
                        db.Entry(L).State = EntityState.Modified;
                        db.SaveChanges();
                        L.Article.Qte_article = L.Article.Qte_article + QteP - L.Quantite;
                        db.Entry(L.Article).State = EntityState.Modified;
                        db.SaveChanges();

                        /* Art.Qte_article = Art.Qte_article + QteP;
                         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 = L.Id_facture });
                    }
                }
            }
            //The model is invalid - render the current view to show any validation errors.
            var articles = db.Article;
            ViewData["articles"] = articles.ToList();

            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("Index", liste_produit.ToList());
        }
        public ActionResult Insert(short idm, string article)
        {
            ModelState.Clear();

            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_vente customer = new Liste_produit_vente
            {
                Id_article = short.Parse(v),
                Id_facture = idm
            };
            Facture_vente Fa = new Facture_vente();
            Fa = db.Facture_vente.Find(idm);

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

                Client client = new Client();

                client = db.Client.Find(db.Facture_vente.Find(idm).Id_client);

                //Perform model binding (fill the customer properties and validate it).
                if (TryUpdateModel(customer))
                {
                    if (Fa.Type_facture.Trim() == "Bon de commande".Trim())
                    {
                        if (client.Categorie_client.Trim() == "Grossiste".Trim())
                        {
                            customer.Prix = Art.Prix_grossiste;
                        }
                        else
                        {
                            customer.Prix = Art.Prix_detaillant;
                        }
                        customer.Prix_Total = customer.Prix * customer.Quantite;
                        db.Liste_produit_vente.Add(customer);
                        db.SaveChanges();
                        return RedirectToAction("Index", new { idm = customer.Id_facture });
                    }
                    else
                    {
                        //The model is valid - insert the customer and redisplay the grid.
                        if (Art.Qte_article < customer.Quantite)
                        {
                            ModelState.AddModelError("", "La quantité est supérieure à la quantité en stock");
                        }
                        else
                        {

                            if (client.Categorie_client.Trim() == "Grossiste".Trim())
                            {
                                customer.Prix = Art.Prix_grossiste;
                            }
                            else
                            {
                                customer.Prix = Art.Prix_detaillant;
                            }

                            customer.Prix_Total = customer.Prix * customer.Quantite;
                            db.Liste_produit_vente.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_facture });
                        }
                    }
                }

                if (customer.Quantite > 0)
                {
                    if (Fa.Type_facture.Trim() == "Bon de commande".Trim())
                    {
                        if (client.Categorie_client.Trim() == "Grossiste".Trim())
                        {
                            customer.Prix = Art.Prix_grossiste;
                        }
                        else
                        {
                            customer.Prix = Art.Prix_detaillant;
                        }
                        customer.Prix_Total = customer.Prix * customer.Quantite;
                        db.Liste_produit_vente.Add(customer);
                        db.SaveChanges();
                        return RedirectToAction("Index", new { idm = customer.Id_facture });
                    }
                    else
                    {
                        if (Art.Qte_article < customer.Quantite)
                        {
                            ModelState.AddModelError("", "La quantité est supérieure à la quantité en stock");
                        }
                        else
                        {
                            if (client.Categorie_client.Trim() == "Grossiste".Trim())
                            {
                                customer.Prix = Art.Prix_grossiste;
                            }
                            else
                            {
                                customer.Prix = Art.Prix_detaillant;
                            }

                            customer.Prix_Total = customer.Prix * customer.Quantite;
                            db.Liste_produit_vente.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();
                            return RedirectToAction("Index", new { idm = customer.Id_facture });
                        }
                    }
                }
            }
            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["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("index", liste_produit.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());
        }
Ejemplo n.º 7
0
        public ActionResult Edit(int id, Facture_vente facture_vente, string type)
        {
            Facture_vente fa = new Facture_vente();
            try
               {
                fa = db.Facture_vente.Find(facture_vente.Id_facture);
                if (facture_vente.Type_facture == "Facture comptabilisée")
                {
                    fa.Type_facture = facture_vente.Type_facture;
                    db.Entry(fa).State = EntityState.Modified;
                    db.SaveChanges();
                    return RedirectToAction("Index");
                }
                else
                {
                    if (fa.Type_facture == "Bon de commande")
                    {
                        Article article = new Article();

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

                        if (VerifQ(lp.ToList()) == true)
                        {
                            ModelState.AddModelError("", "Les quantités en stock ne permettent pas de satisfaire cette démande : transformation impossible");
                            return View(fa);
                        }
                        else
                        {
                            IList<Liste_produit_vente> ListeP = lp.ToList();
                        foreach (Liste_produit_vente listep in ListeP)
                        {
                            listep.Article.Qte_article = listep.Article.Qte_article - listep.Quantite;
                            db.Entry(listep.Article).State = EntityState.Modified;
                            db.SaveChanges();
                        }
                        fa.Type_facture = type;
                        db.Entry(fa).State = EntityState.Modified;
                        db.SaveChanges();
                        return RedirectToAction("Index");

                        }

                        return RedirectToAction("Index");

                    }
                    else
                    {
                        fa.Type_facture = type;
                        db.Entry(fa).State = EntityState.Modified;
                        db.SaveChanges();
                        return RedirectToAction("Index");
                    }

                }
               }
            catch
            {
                return View(fa);
            }
        }
Ejemplo n.º 8
0
        //
        // GET: /FactureA/Edit/5
        public ActionResult Edit(int id)
        {
            Facture_vente facture_vente = new Facture_vente();
            facture_vente = db.Facture_vente.Find(id);

            if (facture_vente.Type_facture.Trim() == "Facture")
                facture_vente.Type_facture = "Facture comptabilisée";
            return View(facture_vente);
        }
Ejemplo n.º 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;
        }