public void When_I_generate_a_receipt_with_quantity_discount() { var sut = new ReceiptGenerator(); var productCatalog = new ProductCatalog(); productCatalog.AddProduct("apple", 0.75m); productCatalog.AddProduct("banana", 1.00m); productCatalog.AddQuantityDiscount("apple", 3, 2.00m); var transaction = new CheckoutTransaction(productCatalog, new Promotions(new List <IPromotionalDiscountRule>() { new AdditionalItemDiscountRule(productCatalog), new QuantityDiscountRule(productCatalog) })); transaction.AddItem("apple"); transaction.AddItem("banana"); transaction.AddItem("apple"); transaction.AddItem("apple"); transaction.AddItem("apple"); transaction.AddItem("apple"); transaction.AddItem("apple"); transaction.AddItem("apple"); var actual = sut.Generate(transaction); Assert.That(actual, Is.EqualTo("Receipt:\n7 apple @ $0.75 is $5.25\n***Discount on apple: Buy 3 apple for $2.00, New Price $4.75, Savings $0.50\n1 banana @ $1.00 is $1.00\nTotal is $5.75")); }
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { if (Receipt.receipt == null) { return; } ReceiptGenerator.printReceipt(Receipt.receipt, e); }
public ActionResult Create(MyNPO.Models.Donation donation) { try { if (ModelState.IsValid) { var guid = Guid.NewGuid(); var dt = DateTime.Now; EntityContext entityContext = new EntityContext(); // Generate the transaction id for cash transactions var existingTransactionsPerDay = entityContext.reportInfo.Where(x => x.Date.Day == DateTime.Today.Day).ToList().Count; var prefixCount = existingTransactionsPerDay <= 0 ? 1 : existingTransactionsPerDay + 1; var transactionId = DateTime.Now.Date.ToString("yyyyMMdd") + "-" + prefixCount; var report = new Report() { Name = donation.Name, TransactionID = transactionId, FromEmailAddress = donation.Email, CurrencyType = donation.DonationType, Net = $"${donation.DonationAmount}", PhoneNo = donation.Phone, Date = dt, Time = dt.ToString(Constants.HourFormat), Description = $"SystemDonation", Reason = donation.Reason, TransactionGuid = guid, ReferenceTxnID = guid.ToString().Replace("-", ""), UploadDateTime = dt, TypeOfReport = Constants.SystemDonation }; entityContext.reportInfo.Add(report); entityContext.SaveChanges(); // TODO: Add insert logic here ModelState.Clear(); ViewBag.Status = "Successfully Saved"; // Generated PDF Receipt and Send email attachment. ReceiptGenerator.GenerateDonationReceiptPdf(donation, report.TransactionID); return(View()); } else { return(View(donation)); } } catch { return(View()); } }
public void can_generate_json_receipt_for_motor_super() { var order = new Order("Test Company"); order.AddLine(new OrderLine(MotorSuper, 1)); var receiptGenerator = new ReceiptGenerator(order, FileFormat.Json); var actual = receiptGenerator.Receipt; var expected = "{\"order-receipt-for\":\"Test Company\",\"orderlines\":[{\"quantity\":\"1\",\"product-type\":\"Car Insurance\",\"product\":{\"name\":\"Super\",\"price\": \"kr 2 000,00\"}}],\"subtotal\": \"kr 2 000,00\",\"mva\":\"kr 500,00\",\"total\":\"kr 2 500,00\"}"; Assert.AreEqual(expected, actual); }
public void can_generate_html_receipt_for_motor_kasko() { var order = new Order("Test Company"); order.AddLine(new OrderLine(MotorKasko, 1)); var receiptGenerator = new ReceiptGenerator(order, FileFormat.Html); var actual = receiptGenerator.Receipt; var expected = $"<html><body><h1>Order receipt for 'Test Company'</h1><ul><li>1 x Car Insurance Kasko = kr 1{System.Globalization.NumberFormatInfo.CurrentInfo.NumberGroupSeparator}000,00</li></ul><h3>Subtotal: kr 1{System.Globalization.NumberFormatInfo.CurrentInfo.NumberGroupSeparator}000,00</h3><h3>MVA: kr 250,00</h3><h2>Total: kr 1{System.Globalization.NumberFormatInfo.CurrentInfo.NumberGroupSeparator}250,00</h2></body></html>"; Assert.AreEqual(expected, actual); }
public void can_generate_receipt_for_motor_kasko() { var order = new Order("Test Company"); order.AddLine(new OrderLine(MotorKasko, 1)); var receiptGenerator = new ReceiptGenerator(order, FileFormat.Text); var actual = receiptGenerator.Receipt; var expected = $"Order receipt for 'Test Company'\r\n\t1 x Car Insurance Kasko 1 = kr 1{System.Globalization.NumberFormatInfo.CurrentInfo.NumberGroupSeparator}000,00\r\nSubtotal: kr 1{System.Globalization.NumberFormatInfo.CurrentInfo.NumberGroupSeparator}000,00\r\nMVA: kr 250,00\r\nTotal: kr 1{System.Globalization.NumberFormatInfo.CurrentInfo.NumberGroupSeparator}250,00"; Assert.AreEqual(expected, actual); }
public void When_I_generate_a_receipt_with_regular_prices() { var sut = new ReceiptGenerator(); var productCatalog = new ProductCatalog(); productCatalog.AddProduct("apple", 0.75m); productCatalog.AddProduct("banana", 1.00m); var transaction = new CheckoutTransaction(productCatalog, new Promotions(new List<IPromotionalDiscountRule>())); transaction.AddItem("apple"); transaction.AddItem("banana"); transaction.AddItem("apple"); var actual = sut.Generate(transaction); Assert.That(actual, Is.EqualTo("Receipt:\n2 apple @ $0.75 is $1.50\n1 banana @ $1.00 is $1.00\nTotal is $2.50")); }
public void When_I_generate_a_receipt_with_regular_prices() { var sut = new ReceiptGenerator(); var productCatalog = new ProductCatalog(); productCatalog.AddProduct("apple", 0.75m); productCatalog.AddProduct("banana", 1.00m); var transaction = new CheckoutTransaction(productCatalog, new Promotions(new List <IPromotionalDiscountRule>())); transaction.AddItem("apple"); transaction.AddItem("banana"); transaction.AddItem("apple"); var actual = sut.Generate(transaction); Assert.That(actual, Is.EqualTo("Receipt:\n2 apple @ $0.75 is $1.50\n1 banana @ $1.00 is $1.00\nTotal is $2.50")); }
public void When_I_generate_a_receipt_with_additional_item_discount() { var sut = new ReceiptGenerator(); var productCatalog = new ProductCatalog(); productCatalog.AddProduct("apple", 0.75m); productCatalog.AddProduct("banana", 1.00m); productCatalog.AddAdditionalItemDiscount("apple", 1, 1, 100); var transaction = new CheckoutTransaction(productCatalog, new Promotions(new List<IPromotionalDiscountRule>() { new AdditionalItemDiscountRule(productCatalog), new QuantityDiscountRule(productCatalog)})); transaction.AddItem("apple"); transaction.AddItem("banana"); transaction.AddItem("apple"); transaction.AddItem("apple"); transaction.AddItem("apple"); transaction.AddItem("apple"); var actual = sut.Generate(transaction); Assert.That(actual, Is.EqualTo("Receipt:\n5 apple @ $0.75 is $3.75\n***Discount on apple: Buy 1 apple get 1 at $0.00, New Price $2.25, Savings $1.50\n1 banana @ $1.00 is $1.00\nTotal is $3.25")); }
private byte[] CreateReceipt() { var rg = new ReceiptGenerator() { SellerName = SiteSetting.Get <string>("Requisites.OrgName"), SellerINN = SiteSetting.Get <string>("Requisites.INN"), SellerAccount = SiteSetting.Get <string>("Requisites.RS"), SellerBank = SiteSetting.Get <string>("Requisites.Bank"), SellerBIK = SiteSetting.Get <string>("Requisites.BIK"), SellerBankAccount = SiteSetting.Get <string>("Requisites.KS"), BuyerAddress = "", BuyerName = User.UserProfile.SurnameAndName, PaymentName = "Оплата заказа №" + ID.ToString("d10"), PaymentTotal = FinalSumWithDelivery }; var bytes = rg.Render(); return(bytes); }
public static void Main(string[] args) { ReceiptGenerator.GenerateYearEndDonationReceiptPdf(); }
public JsonResult Create(FamilyInfo familyInfo) { string status = ""; if (familyInfo.MarriageDate != null) { familyInfo.MaritalStatus = "Married"; } StringBuilder sb = new StringBuilder(); try { // TODO: Add insert logic here Guid transactionId = Guid.NewGuid(); if (familyInfo.MarriageDate == DateTime.MinValue) { familyInfo.MarriageDate = null; } familyInfo.CreateDate = DateTime.Now; familyInfo.PrimaryId = transactionId; var famInfo = entityContext.familyInfos.FirstOrDefault(q => q.FirstName == familyInfo.FirstName && q.LastName == familyInfo.LastName && q.DateOfBirth == familyInfo.DateOfBirth); if (famInfo != null && !string.IsNullOrEmpty(famInfo.FirstName)) { var donorName = $"{familyInfo.FirstName} + ' ' + {familyInfo.LastName}"; status = $"{donorName} is already registered."; if (!string.IsNullOrWhiteSpace(familyInfo.Donation)) { var report = AddedTransactions(familyInfo); if (!string.IsNullOrWhiteSpace(familyInfo.Donation) && !string.IsNullOrWhiteSpace(report.Net)) { entityContext.reportInfo.Add(report); } status += $"--Thanks for the Donation of ${familyInfo.Donation}. "; entityContext.SaveChanges(); // Generated PDF Receipt and Send email attachment. if (!string.IsNullOrWhiteSpace(familyInfo.Donation) && !string.IsNullOrWhiteSpace(report.TransactionID)) { ReceiptGenerator.GenerateDonationReceiptPdf(new Donation() { Name = report.Name, Email = report.FromEmailAddress, DonationAmount = report.Net, DonationType = "Cash", Phone = report.PhoneNo, Reason = report.Reason }, report.TransactionID); status = status + $"we sent the tax recepit to your mentioned mail id"; } } } else { familyInfo?.DependentDetails?.ForEach(s => s.PrimaryId = transactionId); entityContext.familyInfos.Add(familyInfo); var report = AddedTransactions(familyInfo); if (!string.IsNullOrWhiteSpace(familyInfo.Donation) && !string.IsNullOrWhiteSpace(report.Net)) { entityContext.reportInfo.Add(report); } entityContext.SaveChanges(); status = $"Record Saved.--Thanks for the Donation of ${ familyInfo.Donation}. "; // Generated PDF Receipt and Send email attachment. if (!string.IsNullOrWhiteSpace(familyInfo.Donation) && !string.IsNullOrWhiteSpace(report.TransactionID)) { ReceiptGenerator.GenerateDonationReceiptPdf(new Donation() { Name = report.Name, Email = report.FromEmailAddress, DonationAmount = report.Net, DonationType = "Cash", Phone = report.PhoneNo, Reason = report.Reason }, report.TransactionID); status = status + $" We sent the tax recepit to your mentioned mail id"; } } ModelState.Clear(); } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { foreach (var ve in eve.ValidationErrors) { sb.AppendFormat(ve.ErrorMessage + ","); } } return(Json(sb.ToString(), JsonRequestBehavior.AllowGet)); } return(Json(status, JsonRequestBehavior.AllowGet)); }