Пример #1
0
 public void AjouterProduit(Produit produit, int quantite)
 {
     if (produit.Quantite < quantite)
     {
         throw QuantiteInsuffisante();
     }
     DetailsCommandes.Add(new DetailsCommande(produit, quantite, this));
     CalculerTotal();
 }
Пример #2
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);
        }
    }