コード例 #1
0
        //CONSUMER BILL
        public static string GenerateHtmlBillContent(ConsumerBill bill, ApplicationDbContext dbContext)
        {
            StringBuilder builder = new StringBuilder();

            bill.OrderAmount = 0;

            //Entete de facture
            builder.AppendLine("<h2>Commande : " + bill.BillNumber + "</h2>");
            builder.AppendLine("<p>Numéro d'adhérent : " + bill.AdherentStolon.LocalId + "<br>");
            builder.AppendLine("Nom : " + bill.AdherentStolon.Adherent.Name + "<br>");
            builder.AppendLine("Prénom : " + bill.AdherentStolon.Adherent.Surname + "<br>");
            builder.AppendLine("Téléphone : " + bill.AdherentStolon.Adherent.PhoneNumber + "<br>");
            builder.AppendLine("Année : " + DateTime.Now.Year + "<br>");
            builder.AppendLine("Semaine : " + DateTime.Now.GetIso8601WeekOfYear() + "</p>");
            //
            builder.AppendLine("<h2>Produits de votre panier de la semaine :</h2>");
            builder.AppendLine("<table class=\"table\">");
            builder.AppendLine("<tr>");
            builder.AppendLine("<th>Produit</th>");
            builder.AppendLine("<th>Prix unitaire</th>");
            builder.AppendLine("<th>Quantité</th>");
            builder.AppendLine("<th>Prix total</th>");
            builder.AppendLine("</tr>");
            foreach (var tmpBillEntry in bill.BillEntries)
            {
                var     billEntry = dbContext.BillEntrys.Include(x => x.ProductStock).ThenInclude(x => x.Product).First(x => x.Id == tmpBillEntry.Id);
                decimal total     = Convert.ToDecimal(billEntry.UnitPrice * billEntry.Quantity);
                builder.AppendLine("<tr>");
                builder.AppendLine("<td>" + billEntry.Name + "</td>");
                builder.AppendLine("<td>" + billEntry.UnitPrice.ToString("0.00") + " €" + "</td>");
                builder.AppendLine("<td>" + billEntry.QuantityString + "</td>");
                builder.AppendLine("<td>" + total.ToString("0.00") + " €" + "</td>");
                builder.AppendLine("</tr>");
                bill.OrderAmount += total;
            }
            builder.AppendLine("</table>");
            builder.AppendLine("<p>Montant total : " + bill.OrderAmount.ToString("0.00") + " €</p>");
            builder.AddBootstrap();
            builder.AddFooterAndHeaderRemoval();
            return(builder.ToString());
        }
コード例 #2
0
        //PRODUCER BILL

        private static string GenerateHtmlOrderContent(ProducerBill bill, ApplicationDbContext dbContext)
        {
            //GENERATION COMMANDE
            StringBuilder orderBuilder = new StringBuilder();

            //Entete de facture
            //  Producteur
            orderBuilder.AppendLine("<h2> Commande n°" + bill.OrderNumber + "</h2>");
            orderBuilder.AppendLine("<p>" + bill.AdherentStolon.Adherent.CompanyName + "<br>");
            orderBuilder.AppendLine("<Année : " + DateTime.Now.Year + "<br>");
            orderBuilder.AppendLine("Semaine : " + DateTime.Now.GetIso8601WeekOfYear() + "<br></p>");
            orderBuilder.AppendLine("<br>");
            #region Par produit

            orderBuilder.AppendLine("<h3>Commande par produit</h3>");

            orderBuilder.AppendLine("<table class=\"table\">");
            orderBuilder.AppendLine("<tr>");
            orderBuilder.AppendLine("<th>Produit</th>");
            orderBuilder.AppendLine("<th>Quantité</th>");
            orderBuilder.AppendLine("</tr>");

            foreach (var productBillEntries in bill.BillEntries.GroupBy(x => x.ProductStock.Product, x => x).OrderBy(x => x.Key.Name))
            {
                int quantity = 0;
                productBillEntries.ForEach(x => quantity += x.Quantity);
                orderBuilder.AppendLine("<tr>");
                orderBuilder.AppendLine("<td>" + productBillEntries.Key.Name + "</td>");
                orderBuilder.AppendLine("<td>" + productBillEntries.Key.GetQuantityString(quantity) + "</td>");
                orderBuilder.AppendLine("</tr>");
            }
            orderBuilder.AppendLine("</table>");

            #endregion Par produit

            #region Par client
            orderBuilder.AppendLine("<h3>Commande par client</h3>");

            var billEntriesByConsumer = bill.BillEntries.GroupBy(x => x.ConsumerBill.AdherentStolon);
            orderBuilder.AppendLine("<table class=\"table\">");
            orderBuilder.AppendLine("<tr>");
            orderBuilder.AppendLine("<th>Client</th>");
            orderBuilder.AppendLine("<th>Produit</th>");
            orderBuilder.AppendLine("<th>Quantité</th>");
            orderBuilder.AppendLine("</tr>");
            foreach (var group in billEntriesByConsumer.OrderBy(x => x.Key.LocalId))
            {
                orderBuilder.AppendLine("<tr>");
                orderBuilder.AppendLine("<td colspan=\"3\" style=\"border-top:1px solid;\">" + "<b>" + group.Key.LocalId + "</b>" + "</td>");
                orderBuilder.AppendLine("</tr>");
                foreach (var entries in group.OrderBy(x => x.ProductStock.ProductId))
                {
                    orderBuilder.AppendLine("<tr>");
                    orderBuilder.AppendLine("<td></td>");
                    orderBuilder.AppendLine("<td>" + entries.Name + "</td>");
                    orderBuilder.AppendLine("<td>" + entries.QuantityString + "</td>");
                    orderBuilder.AppendLine("</tr>");
                }
            }
            orderBuilder.AppendLine("</table>");

            #endregion Par client

            orderBuilder.AppendLine("<h3>Facturation</h3>");
            orderBuilder.AppendLine("<p>" + "Montant total de la commande  " + bill.OrderAmount.ToString("0.00") + "€<br>");
            orderBuilder.AppendLine("Montant total du % du Stolons " + bill.FeeAmount.ToString("0.00") + "€<br>");
            orderBuilder.AppendLine("Montant total à percevoir     <b>" + bill.BillAmount.ToString("0.00") + "€</b> <i>(Dont " + bill.TaxAmount.ToString("0.00") + "€ TVA)</i></p>");
            orderBuilder.AddBootstrap();
            orderBuilder.AddFooterAndHeaderRemoval();
            return(orderBuilder.ToString());
        }
コード例 #3
0
        public static string GenerateHtmlBillContent(ProducerBill bill, ApplicationDbContext dbContext)
        {
            //Calcul total amount
            decimal totalAmount = 0;

            foreach (var billEntry in bill.BillEntries)
            {
                totalAmount += billEntry.Price;
            }
            bill.OrderAmount  = totalAmount;
            bill.ProducersFee = bill.AdherentStolon.Stolon.ProducersFee;

            //GENERATION FACTURE
            StringBuilder billBuilder = new StringBuilder();

            //Entete de facture
            //  Producteur
            billBuilder.AppendLine("<p>" + bill.AdherentStolon.Adherent.CompanyName + "<p>");
            billBuilder.AppendLine("<p>" + bill.AdherentStolon.Adherent.Surname?.ToUpper() + " " + bill.AdherentStolon.Adherent.Name?.ToUpper() + "<p>");
            billBuilder.AppendLine("<p>" + bill.AdherentStolon.Adherent.Address + "</p>");
            billBuilder.AppendLine("<p>" + bill.AdherentStolon.Adherent.PostCode + " " + bill.AdherentStolon.Adherent.City?.ToUpper() + "</p>");
            billBuilder.AppendLine("<br>");
            billBuilder.AppendLine("<p>Facture n° " + bill.BillNumber + "</p>");
            billBuilder.AppendLine("<p>Année : " + DateTime.Now.Year);
            billBuilder.AppendLine("<p>Semaine : " + DateTime.Now.GetIso8601WeekOfYear());

            billBuilder.AppendLine("<br>");
            billBuilder.AppendLine("<table class=\"table\">");
            billBuilder.AppendLine("<tr>");
            billBuilder.AppendLine("<th>Produit</th>");
            billBuilder.AppendLine("<th>Quantité</th>");
            billBuilder.AppendLine("<th>TVA</th>");
            billBuilder.AppendLine("<th>PU HT</th>");
            billBuilder.AppendLine("<th>TOTAL HT</th>");
            billBuilder.AppendLine("</tr>");
            //Taux tax / Total HT
            Dictionary <decimal, decimal> taxTotal = new Dictionary <decimal, decimal>();
            decimal totalWithoutTax = 0;

            foreach (var productBillEntries in bill.BillEntries.GroupBy(x => x.ProductStock.Product, x => x).OrderBy(x => x.Key.Name))
            {
                int quantity = 0;
                productBillEntries.ForEach(x => quantity += x.Quantity);
                decimal productTotalWithoutTax = Convert.ToDecimal(productBillEntries.First().UnitPriceWithoutFeeAndTax *quantity);
                billBuilder.AppendLine("<tr>");
                billBuilder.AppendLine("<td>" + productBillEntries.Key.Name + "</td>");
                billBuilder.AppendLine("<td>" + productBillEntries.Key.GetQuantityString(quantity) + "</td>");
                billBuilder.AppendLine("<td>" + (productBillEntries.Key.TaxEnum == Product.TAX.None ? "NA" : productBillEntries.Key.Tax.ToString()) + " %</td>");
                billBuilder.AppendLine("<td>" + (productBillEntries.Key.Type == SellType.Piece ? productBillEntries.First().UnitPriceWithoutFeeAndTax : productBillEntries.First().PriceWithoutFeeAndTax) + " €" + "</td>");
                billBuilder.AppendLine("<td>" + productTotalWithoutTax.ToString("0.00") + " €" + "</td>");
                billBuilder.AppendLine("</tr>");
                //Si tax, on ajoute au total du taux de la tva
                if (productBillEntries.Key.TaxEnum != Product.TAX.None)
                {
                    if (taxTotal.ContainsKey(productBillEntries.Key.Tax))
                    {
                        taxTotal[productBillEntries.Key.Tax] += productTotalWithoutTax;
                    }
                    else
                    {
                        taxTotal.Add(productBillEntries.Key.Tax, productTotalWithoutTax);
                    }
                }
                totalWithoutTax += productTotalWithoutTax;
            }
            billBuilder.AppendLine("<tr>");
            billBuilder.AppendLine("<td></td>");
            billBuilder.AppendLine("<td></td>");
            billBuilder.AppendLine("<td></td>");
            billBuilder.AppendLine("<td>Total HT</td>");
            billBuilder.AppendLine("<td>" + totalWithoutTax.ToString("0.00") + " €</td>");
            billBuilder.AppendLine("</tr>");
            bill.TaxAmount = 0;
            foreach (var tax in taxTotal)
            {
                decimal taxAmount = Math.Round(tax.Value / 100m * tax.Key, 2);
                billBuilder.AppendLine("<tr>");
                billBuilder.AppendLine("<td></td>");
                billBuilder.AppendLine("<td></td>");
                billBuilder.AppendLine("<td></td>");
                billBuilder.AppendLine("<td>TVA " + tax.Key + "%</td>");
                billBuilder.AppendLine("<td>" + taxAmount.ToString("0.00") + " €</td>");
                billBuilder.AppendLine("</tr>");
                bill.TaxAmount += taxAmount;
            }
            billBuilder.AppendLine("<tr>");
            billBuilder.AppendLine("<td></td>");
            billBuilder.AppendLine("<td></td>");
            billBuilder.AppendLine("<td></td>");
            billBuilder.AppendLine("<td>Net à payer</td>");
            billBuilder.AppendLine("<td>" + bill.BillAmount.ToString("0.00") + " €</td>");
            billBuilder.AppendLine("</tr>");
            billBuilder.AppendLine("</table>");

            billBuilder.AddBootstrap();
            billBuilder.AddFooterAndHeaderRemoval();

            return(billBuilder.ToString());
        }
コード例 #4
0
        private static StolonsBill GenerateBill(Stolon stolon, List <ConsumerBill> consumersBills, ApplicationDbContext dbContext)
        {
            StringBuilder builder    = new StringBuilder();
            string        billNumber = stolon.ShortLabel + "_" + DateTime.Now.Year + "_" + DateTime.Now.GetIso8601WeekOfYear();
            StolonsBill   bill       = new StolonsBill(billNumber)
            {
                Stolon       = stolon,
                Amount       = 0,
                ProducersFee = stolon.ProducersFee,
                Consumers    = consumersBills.Count
            };

            if (!consumersBills.Any())
            {
                builder.AppendLine("Rien cette semaine !");
            }
            else
            {
                builder.AppendLine("<h1>Commandes numéro : " + billNumber + "</h1>");
                builder.AppendLine("<p>Année : " + DateTime.Now.Year);
                builder.AppendLine("<br>Semaine : " + DateTime.Now.GetIso8601WeekOfYear());
                builder.AppendLine("<br><b>Nombre de panier : " + consumersBills.Count + "</b></p>");
                builder.AppendLine("<p>Adhérents ayant un panier : <small><br>");
                consumersBills.OrderBy(x => x.AdherentStolon.LocalId)
                .ForEach(x => builder.AppendLine("<a href=\"#" + x.AdherentStolon.LocalId + "\">" + x.AdherentStolon.GetNumberSurnameName() + "</a><br>"));
                builder.AppendLine("</small></p>");

                builder.AppendLine("<div style=\"page-break-after:always\"></div>");
                int count = 0;
                foreach (var consumerBill in consumersBills.OrderBy(x => x.AdherentStolon.LocalId))
                {
                    count++;
                    builder.AppendLine("<h1 id=\"" + consumerBill.AdherentStolon.LocalId + "\">Adhérent : " + consumerBill.AdherentStolon.LocalId + " / " + consumerBill.AdherentStolon.Adherent.Surname + " / " + consumerBill.AdherentStolon.Adherent.Name + "</h1>");
                    builder.AppendLine("<p>Facture : " + consumerBill.BillNumber + "</p>");
                    builder.AppendLine("<p>Téléphone : " + consumerBill.AdherentStolon.Adherent.PhoneNumber + "</p>");
                    builder.AppendLine("<p>Total à régler : " + consumerBill.TotalPrice.ToString("0.00") + " €</p>");

                    //Create list of bill entry by product
                    var billEntryByProducer = consumerBill.BillEntries.GroupBy(x => x.ProducerBill);

                    builder.AppendLine("<h2>Commande par producteur</h2>");

                    builder.AppendLine("<table class=\"table\">");
                    builder.AppendLine("<tr>");
                    builder.AppendLine("<th>Producteur</th>");
                    builder.AppendLine("<th>Produit</th>");
                    builder.AppendLine("<th>Quantité</th>");
                    builder.AppendLine("</tr>");

                    foreach (var producerBillsEntry in billEntryByProducer.OrderBy(x => x.Key.AdherentStolon.Adherent.CompanyName))
                    {
                        builder.AppendLine("<tr>");
                        builder.AppendLine("<td colspan=\"3\" style=\"border-top:1px solid;\">" + "<b>" + producerBillsEntry.Key.AdherentStolon.Adherent.CompanyName + "</b>" + "</td>");
                        builder.AppendLine("</tr>");
                        foreach (var billEntry in producerBillsEntry.OrderBy(x => x.ProductStock.Product.Name))
                        {
                            builder.AppendLine("<tr>");
                            builder.AppendLine("<td></td>");
                            builder.AppendLine("<td>" + billEntry.ProductStock.Product.Name + "</td>");
                            builder.AppendLine("<td>" + billEntry.QuantityString + "</td>");
                            builder.AppendLine("</tr>");
                        }
                    }
                    builder.AppendLine("</table>");
                    if (count != consumersBills.Count)
                    {
                        builder.AppendLine("<div style=\"page-break-after:always\"></div>");
                    }
                }


                /*
                 * foreach (ValidatedWeekBasket tempWeekBasket in consumerWeekBaskets.OrderBy(x => x.AdherentStolon.LocalId))
                 * {
                 * ValidatedWeekBasket weekBasket = dbContext.ValidatedWeekBaskets.Include(x => x.BillEntries).First(x => x.Id == tempWeekBasket.Id);
                 * weekBasket.BillEntries.ForEach(x => x = dbContext.BillEntrys.First(b => b.Id == x.Id));
                 * bill.Amount += weekBasket.TotalPrice;
                 * //
                 * builder.AppendLine("<h1>Adhérent : " + weekBasket.AdherentStolon.LocalId + " / " + weekBasket.Adherent.Surname + " / " + weekBasket.Adherent.Name + "</h1>");
                 * builder.AppendLine("<p>Facture : " + billNumber + "_" + weekBasket.Consumer.Id + "</p>");
                 * builder.AppendLine("<p>Téléphone : " + weekBasket.Consumer.PhoneNumber + "</p>");
                 * builder.AppendLine("<p>Total à régler : " + weekBasket.TotalPrice.ToString("0.00") + " €</p>");
                 *
                 *
                 * //Create list of bill entry by product
                 * Dictionary<Adherent, List<BillEntry>> producersProducts = new Dictionary<Adherent, List<BillEntry>>();
                 * foreach (var billEntryConsumer in weekBasket.BillEntries)
                 * {
                 * var billEntry = dbContext.BillEntrys.Include(x => x.Product).ThenInclude(x => x.Producer).First(x => x.Id == billEntryConsumer.Id);
                 * if (!producersProducts.ContainsKey(billEntry.Product.Producer))
                 * {
                 * producersProducts.Add(billEntry.Product.Producer, new List<BillEntry>());
                 * }
                 * producersProducts[billEntry.Product.Producer].Add(billEntry);
                 * }
                 * List<int> rowsTotal = new List<int>();
                 * // - Add products by producer
                 * builder.AppendLine("<h2>Commande par producteur</h2>");
                 *
                 * builder.AppendLine("<table class=\"table\">");
                 * builder.AppendLine("<tr>");
                 * builder.AppendLine("<th>Producteur</th>");
                 * builder.AppendLine("<th>Produit</th>");
                 * builder.AppendLine("<th>Quantité</th>");
                 * builder.AppendLine("</tr>");
                 *
                 * foreach (var producer in producersProducts.Keys.OrderBy(x => x.Id))
                 * {
                 * builder.AppendLine("<tr>");
                 * builder.AppendLine("<td colspan=\"3\" style=\"border-top:1px solid;\">" + "<b>" + producer.CompanyName + "</b>" + "</td>");
                 * builder.AppendLine("</tr>");
                 * foreach (var billEntry in producersProducts[producer].OrderBy(x => x.Product.Name))
                 * {
                 * builder.AppendLine("<tr>");
                 * builder.AppendLine("<td></td>");
                 * builder.AppendLine("<td>" + billEntry.Product.Name + "</td>");
                 * builder.AppendLine("<td>" + billEntry.QuantityString + "</td>");
                 * builder.AppendLine("</tr>");
                 *
                 * }
                 * }
                 * builder.AppendLine("</table>");
                 * builder.AppendLine("<divstyle=\"page-break-after:always;\">");
                 * }
                 */
            }
            builder.AddBootstrap();
            builder.AddFooterAndHeaderRemoval();
            bill.HtmlBillContent = builder.ToString();
            //TODO envisager de créer les HtmlBillContent via des cshtml plutot que comme ca

            return(bill);
        }