public ActionResult TakePaymentByCar(DefaultSettingViewModel model) { int carId = 0; BillGenerator obj = new BillGenerator(); DateTime serviceDate = DateTime.Now.Date.AddDays(1); var currentDay = DateTime.Now.Date.AddDays(1).DayOfWeek.ToString(); var userSuppliedAuthor = new SqlParameter("@ServiceDate", serviceDate); var result = db.Database.SqlQuery <Garage_CarDaySettingPaymentDetailModel>("exec dbo.GetGarage_CarDaySettingPaymentDetail @ServiceDate", userSuppliedAuthor).ToList(); if (result.Count > 0) { foreach (var item in result) { carId = 0; // Skip if payment is already paid (True). if (item.IsPaid) { continue; } foreach (string key in Request.Form.Keys) { if (key == "btnMakePayment-" + item.CarId) { carId = item.CarId; } } if (carId > 0) { // Other wise take payment from paypal. try { string responsePayment = obj.TakePaymentFromPaypal(item.UserPackageID, item.BillingAggrementID, item.CarServiceDate, item.JobId); string text = "Paypal Call: " + DateTime.Now.ToString(); text += Environment.NewLine + Environment.NewLine + "responseFrom Paypal: " + responsePayment; string fileName = item.JobId + "-" + item.UserPackageID + "-" + item.BillingAggrementID + "__" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm", CultureInfo.InvariantCulture) + ".txt"; System.IO.File.WriteAllText(Server.MapPath("~/App_Data/" + fileName), text); } catch (Exception ex) { string fileName = "ErrorLog_" + item.JobId + "-" + item.UserPackageID + "-" + item.BillingAggrementID + "__" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm", CultureInfo.InvariantCulture) + ".txt"; System.IO.File.WriteAllText(Server.MapPath("~/App_Data/" + fileName), ex.ToString()); } break; } } } return(RedirectToAction("Index", new { Id = model.GarageId })); }
private static Bill GenerateBill(Root config, PriceList priceList, ShoppingCart.ShoppingCart shoppingCart) { MainOfferHandler mainOfferHandler = new MainOfferHandler(config.GetOffers(), priceList); BillGenerator billGenerator = new BillGenerator(priceList, mainOfferHandler); Bill bill = billGenerator.GenerateBill(shoppingCart); return(bill); }
public string RegenerateOrders() { var stolon = GetCurrentStolon(); var consumersBills = _context.ConsumerBills .Include(x => x.AdherentStolon) .Include(x => x.AdherentStolon.Adherent) .Include(x => x.AdherentStolon.Stolon) .Where(x => x.State == BillState.Pending && x.AdherentStolon.StolonId == stolon.Id) .OrderBy(x => x.AdherentStolon.Adherent.Id) .ToList(); var producersBills = _context.ProducerBills .Include(x => x.AdherentStolon) .Include(x => x.AdherentStolon.Adherent) .Include(x => x.AdherentStolon.Stolon) .Where(x => x.State != BillState.Paid && x.AdherentStolon.StolonId == stolon.Id) .OrderBy(x => x.AdherentStolon.Adherent.Id) .ToList(); var weekStolonBill = _context.StolonsBills .Include(x => x.Stolon) .Where(x => x.StolonId == stolon.Id) .ToList() .FirstOrDefault(x => x.BillNumber.EndsWith(DateTime.Now.Year + "_" + DateTime.Now.GetIso8601WeekOfYear())); DateTime start = DateTime.Now; StringBuilder report = new StringBuilder(); report.Append("Rapport de génération des commandes : "); report.AppendLine("- stolon : " + stolon.Label); report.AppendLine("- année : " + DateTime.Now.Year); report.AppendLine("- semaine : " + DateTime.Now.GetIso8601WeekOfYear()); report.AppendLine(); Dictionary <ConsumerBill, bool> consumers = new Dictionary <ConsumerBill, bool>(); consumersBills.ForEach(x => consumers.Add(x, BillGenerator.GenerateBillPDF(x))); Dictionary <ProducerBill, bool> producers = new Dictionary <ProducerBill, bool>(); producersBills.ForEach(x => producers.Add(x, BillGenerator.GenerateOrderPDF(x))); bool stolonBill = BillGenerator.GeneratePDF(weekStolonBill.HtmlBillContent, weekStolonBill.FilePath); report.AppendLine("RESUME : "); report.AppendLine("Commandes consomateurs générées : " + consumers.Count(x => x.Value == true) + "/" + consumers.Count); report.AppendLine("Commandes producteurs générées : " + producers.Count(x => x.Value == true) + "/" + producers.Count); report.AppendLine("Commandes stolons générées : " + stolonBill); report.AppendLine("DETAILS : "); report.AppendLine("-- Consomateurs ok : "); consumers.Where(x => x.Value).ToList().ForEach(consumer => report.AppendLine(consumer.Key.AdherentStolon.LocalId + " " + consumer.Key.AdherentStolon.Adherent.Name.ToUpper() + " " + consumer.Key.AdherentStolon.Adherent.Surname)); report.AppendLine("-- Consomateurs nok : "); consumers.Where(x => x.Value == false).ToList().ForEach(consumer => report.AppendLine(consumer.Key.AdherentStolon.LocalId + " " + consumer.Key.AdherentStolon.Adherent.Name.ToUpper() + " " + consumer.Key.AdherentStolon.Adherent.Surname)); report.AppendLine("-- Producteurs ok : "); producers.Where(x => x.Value).ToList().ForEach(producer => report.AppendLine(producer.Key.AdherentStolon.LocalId + " " + producer.Key.AdherentStolon.Adherent.Name.ToUpper() + " " + producer.Key.AdherentStolon.Adherent.Surname)); report.AppendLine("-- Producteurs nok : "); producers.Where(x => x.Value == false).ToList().ForEach(producer => report.AppendLine(producer.Key.AdherentStolon.LocalId + " " + producer.Key.AdherentStolon.Adherent.Name.ToUpper() + " " + producer.Key.AdherentStolon.Adherent.Surname)); report.AppendLine(); report?.AppendLine(" --Temps d'execution de la génération : " + (DateTime.Now - start)); return(report.ToString()); }
public FileResult TestPDF() { string tempFilePath = Path.Combine(Configurations.Environment.WebRootPath, "temp", "test.pdf"); BillGenerator.GeneratePDF("Test de la génération d'un PDF", tempFilePath); byte[] fileBytes = System.IO.File.ReadAllBytes(tempFilePath); return(File(fileBytes, "application/pdf", "test.pdf")); }
public IActionResult Create([Bind("Id,ItemId,Count")] BillGenerator billGenerator) { if (ModelState.IsValid) { _uow.BillGeneratorRepository.AddBill(billGenerator.ItemId, billGenerator.Count); return(RedirectToAction(nameof(Index))); } return(View(billGenerator)); }
public void Statement_unknown_playtype_should_throw_exception() { const string invalidPlayId = "invalid"; var plays = new PlaysBuilder() .WithPlay(invalidPlayId, (PlayType)99) .Build(); var invoice = new InvoiceBuilder() .WithPerformance(invalidPlayId, 1) .Build(); var generator = new BillGenerator(); Action act = () => generator.Statement(invoice, plays); act.Should().Throw <Exception>().WithMessage("unknown type: 99"); }
public ActionResult TestAutoPay() { string responsePayment = string.Empty; BillGenerator obj = new BillGenerator(); responsePayment = obj.TestAutoPayment(); string text = "Paypal Call: " + DateTime.Now.ToString(); text += Environment.NewLine + Environment.NewLine + "responseFrom Paypal: " + responsePayment; string fileName = DateTime.Now.ToString("yyyy-MM-dd-HH-mm", CultureInfo.InvariantCulture) + ".txt"; System.IO.File.WriteAllText(Server.MapPath("~/App_Data/" + fileName), text); return(Content("")); }
public void Discount_Test() { BillFactory factory = new BillFactory(); Goods cola = factory.Create("Special", "Cola"); Item i1 = new Item(cola, 6, 65); Customer x = new Customer("Vadim&Volodya", 10); IPresenter p = new TXTPresenter(); BillGenerator b1 = new BillGenerator(x, p); b1.addGoods(i1); string bill = b1.GenerateBill(); double actual = b1.discount_1; double exepted = 13.9; Assert.AreEqual(exepted, actual); }
public void Bonus_Test() { BillFactory factory = new BillFactory(); Goods cola = factory.Create("Special", "Cola"); Goods pepsi = factory.Create("Sale", "Pepsi"); Item i1 = new Item(cola, 6, 65); Item i2 = new Item(pepsi, 3, 50); Customer x = new Customer("Vadim&Volodya", 10); IPresenter p = new TXTPresenter(); BillGenerator b1 = new BillGenerator(x, p); b1.addGoods(i1); b1.addGoods(i2); string bill = b1.GenerateBill(); double actual = b1.bonus; double exepted = 10; Assert.AreEqual(exepted, actual); }
public ActionResult ApplicationDetails(FormCollection collection) { Bill toAdd = BillGenerator.GenerateBill(collection); using (HttpClient client = WebApiClient.InitializeClient(Request.Url.Scheme + "://" + Request.Url.Authority + Request.ApplicationPath.TrimEnd('/') + "/")) { JsonMediaTypeFormatter formatter = new JsonMediaTypeFormatter(); formatter.SerializerSettings.TypeNameHandling = TypeNameHandling.All; HttpResponseMessage response = client.PostAsync("api/Bill", toAdd, formatter).Result; if (response.IsSuccessStatusCode) { return(RedirectToAction("ApplicationDetails", "Service", new { id = toAdd.ApplicationId })); } } return(RedirectToAction("Index")); }
public void BaseTest() { BillFactory factory = new BillFactory(); Goods fanta = factory.Create("Regular", "Fanta"); Goods snikers = factory.Create("Sale", "snikers"); int price_for_fanta = 45; int price_for_snikers = 33; Item i1 = new Item(fanta, 2, price_for_fanta); Item i2 = new Item(snikers, 3, price_for_snikers); Customer Denis = new Customer("Vadim&Volodya", 10); IPresenter p = new TXTPresenter(); BillGenerator b1 = new BillGenerator(Denis, p); b1.addGoods(i1); b1.addGoods(i2); string bill = b1.GenerateBill(); string actual = bill; string exepted = b1.GenerateBill(); Assert.AreEqual(exepted, actual); }
public void HTML_Presenter_test() { BillFactory factory = new BillFactory(); Goods cola = factory.Create("Regular", "Cola"); Goods pepsi = factory.Create("Sale", "Pepsi"); int price_for_fanta = 45; int price_for_snikers = 33; Item i1 = new Item(cola, 2, price_for_fanta); Item i2 = new Item(pepsi, 3, price_for_snikers); Customer Denis = new Customer("Vadim&Volodya", 10); IPresenter p = new HTMLPresenter(); BillGenerator b1 = new BillGenerator(Denis, p); b1.addGoods(i1); b1.addGoods(i2); string bill = b1.GenerateBill(); string actual = bill; string exepted = b1.GenerateBill(); Assert.AreEqual(exepted, actual); }
public bool UpdateBillCorrection(VmBillCorrection billCorrection) { billCorrection.Reason = "Modification le : " + DateTime.Now.ToString() + "\n\rRaison : " + billCorrection.Reason + "\n\r\n\r"; ProducerBill bill = _context.ProducerBills.Include(x => x.BillEntries).Include(x => x.AdherentStolon).First(x => x.BillId == billCorrection.ProducerBillId); bill.ModificationReason = billCorrection.Reason; bill.HasBeenModified = true; List <Guid?> modifiedBills = new List <Guid?>(); foreach (var billQuantity in billCorrection.NewQuantities) { var billEntry = bill.BillEntries.First(x => x.Id == billQuantity.BillId); billEntry.Quantity = billQuantity.Quantity; billEntry.HasBeenModified = true; if (!modifiedBills.Any(x => x == billEntry.ConsumerBillId)) { modifiedBills.Add(billEntry.ConsumerBillId); } } _context.SaveChanges(); bill = _context.ProducerBills.Include(x => x.BillEntries).Include(x => x.AdherentStolon).Include(x => x.AdherentStolon.Stolon).Include(x => x.AdherentStolon.Adherent).First(x => x.BillId == billCorrection.ProducerBillId); bill.BillEntries.ForEach(x => x.ProductStock = _context.ProductsStocks.Include(y => y.Product).First(stock => stock.Id == x.ProductStockId)); bill.HtmlBillContent = BillGenerator.GenerateHtmlBillContent(bill, _context); BillGenerator.GenerateBillPDF(bill); foreach (var billId in modifiedBills) { var billToModify = _context.ConsumerBills.Include(x => x.AdherentStolon.Adherent).First(x => x.BillId == billId); billToModify.ModificationReason += billCorrection.Reason; billToModify.HasBeenModified = true; //Envoie mail user BillGenerator.GenerateBillPDF(billToModify); AuthMessageSender.SendEmail(billToModify.AdherentStolon.Stolon.Label, billToModify.AdherentStolon.Adherent.Email, billToModify.AdherentStolon.Adherent.CompanyName, "Votre bon de commande de la semaine chez " + billToModify.AdherentStolon.Stolon.Label + "a été modifié (Bon de commande " + bill.BillNumber + ")", "Oops, petit problème, malheureusement tout vos produits ne pourront pas être disponible. Votre commande a été modifié. En voici la raison : " + billCorrection.Reason + "\n\n" + bill.HtmlBillContent); } _context.SaveChanges(); return(true); }
public void BaseTest_3() { BillFactory factory = new BillFactory(); Goods beer = factory.Create("Sale", "Beer"); Goods chips = factory.Create("Special", "Chips"); Goods nuts = factory.Create("Sale", "Nuts"); Item i1 = new Item(beer, 2, 67); Item i2 = new Item(chips, 4, 45); Item i3 = new Item(nuts, 2, 27); IPresenter p = new TXTPresenter(); Customer x = new Customer("Vadim&Volodya", 15); BillGenerator b1 = new BillGenerator(x, p); b1.addGoods(i1); b1.addGoods(i2); b1.addGoods(i3); string bill = b1.GenerateBill(); double actual = b1.f; double exepted = 351.19999999999999; Assert.AreEqual(exepted, actual); }
public static void Main(string[] args) { var host = BuildWebHost(args); //Register webhost in Stolons configs Configurations.WebHost = host; Thread billManager = new Thread(() => BillGenerator.ManageBills()); billManager.Start(); var logger = DotnetHelper.GetLogger <Program>(); using (var scope = DotnetHelper.GetNewScope()) { var services = scope.ServiceProvider; try { Startup.SeedDatabase(services); } catch (Exception ex) { logger.LogError(ex, "An error occurred seeding the DB."); } } try { host.Run(); } catch (Exception e) { logger.LogError("Server is dead, catched exception. Bye cruel world"); throw e; } }
public void RenderPlainTextTest() { var plays = new PlaysBuilder().Build(); var invoice = new InvoiceBuilder() .ForCustomer("BigCo") .WithPerformance("hamlet", 55) .WithPerformance("as-like", 35) .WithPerformance("othello", 40) .Build(); var generator = new BillGenerator(); var statement = generator.Statement(invoice, plays); statement.Should().Be(@"Statement for BigCo Hamlet: $650.00 (55 seats) As You Like It: $580.00 (35 seats) Othello: $500.00 (40 seats) Amount owed is $1,660.80 You earned 47 credits"); }
public static void OnShutdown() { DotnetHelper.GetLogger <Startup>().LogWarning("Server is shutting down"); BillGenerator.StopThread(); }