/// <summary> /// Create new ReceiptDTO model /// </summary> private LineReceiptDTO CreateReceiptDTOModel(Customer customer, Line line, Payment linePayment) { LineReceiptDTO newReceipt = new LineReceiptDTO(linePayment); newReceipt.CustomerName = $"{customer.FirstName} {customer.LastName}"; newReceipt.LineNumber = line.LineNumber; int usageCallMinute = newReceipt.UsageCall; newReceipt.MinutesBeyondPackageLimit = TimeSpan.FromMinutes(linePayment.MinutesBeyondPackageLimit); newReceipt.LeftMinutes = newReceipt.PackageMinute - usageCallMinute < 0 ? TimeSpan.Zero : TimeSpan.FromMinutes(newReceipt.PackageMinute - usageCallMinute); newReceipt.LeftSms = newReceipt.PackageMinute - usageCallMinute < 0 ? 0 : newReceipt.PackageSms - newReceipt.UsageSms; newReceipt.MinutesUsagePrecent = newReceipt.PackageMinute == 0 ? 0 : (100 - (int)((newReceipt.LeftMinutes.TotalMinutes / newReceipt.PackageMinute) * 100)); newReceipt.SmsUsagePrecent = newReceipt.PackageSms == 0 ? 0 : (100 - (int)((newReceipt.LeftSms / newReceipt.PackageSms) * 100)); newReceipt.PricePerMinute = customer.CustomerType.MinutePrice; newReceipt.PricePerSms = customer.CustomerType.SmsPrice; newReceipt.ExceptionalMinutesPrice = newReceipt.MinutesBeyondPackageLimit.TotalMinutes * newReceipt.PricePerMinute; newReceipt.ExceptionalSmsPrice = newReceipt.SmsBeyondPackageLimit * newReceipt.PricePerSms; return(newReceipt); }
/// <summary> /// Produces an invoice for the customer according to all the lines in his possession /// </summary> /// <param name="idCard">Customer identity card</param> /// <param name="date">Requested month and year</param> /// <returns>List of customer line's receipts if succeeded otherwise null</returns> public List <LineReceiptDTO> GetCustomerReceipt(string idCard, DateTime date) { List <LineReceiptDTO> receipts = new List <LineReceiptDTO>(); Customer customer; customer = _unitOfWork.Customer.GetCustomerWithTypeLinesAndPayment(idCard); if (customer != null) { foreach (var line in customer.Lines) { Payment linePayment = line.Payments.Where((p) => p.Date.Year == date.Year && p.Date.Month == date.Month).SingleOrDefault(); if (linePayment != null) //Create new receipt according to payment details { LineReceiptDTO newReceipt = CreateReceiptDTOModel(customer, line, linePayment); receipts.Add(newReceipt); } } } return(receipts); }
private PdfPTable CreateLineTable(LineReceiptDTO receipt) { PdfPTable table = new PdfPTable(3) { WidthPercentage = 100 }; PdfPCell cell = new PdfPCell(new Phrase("Line Number:" + receipt.LineNumber)); cell.Colspan = 3; cell.HorizontalAlignment = Element.ALIGN_CENTER; table.AddCell(cell); table.AddCell("Total line price: " + receipt.LineTotalPrice + "₪"); cell = new PdfPCell(new Phrase("Package info:")); cell.Colspan = 2; table.AddCell(cell); cell = new PdfPCell(new Phrase("Package")); cell.Colspan = 3; cell.HorizontalAlignment = Element.ALIGN_LEFT; table.AddCell(cell); table.AddCell("Minute: " + receipt.UsageCall); // "Row 4, Col 1" table.AddCell("Minute left: " + receipt.LeftMinutes); // "Row 4, Col 2" table.AddCell("Package used: " + receipt.MinutesUsagePrecent + "%"); // "Row 4, Col 3" table.AddCell("SMS: " + receipt.UsageSms); // "Row 5, Col 1" table.AddCell("SMS left: " + receipt.LeftSms); // "Row 5, Col 2" table.AddCell("Package used: " + receipt.SmsUsagePrecent + "%"); // "Row 5, Col 3" cell = new PdfPCell(new Phrase("Package price: " + receipt.PackagePrice + "₪")); cell.Colspan = 3; cell.HorizontalAlignment = Element.ALIGN_CENTER; table.AddCell(cell); cell = new PdfPCell(new Phrase("Out of Package")); cell.Colspan = 3; cell.HorizontalAlignment = Element.ALIGN_LEFT; table.AddCell(cell); table.AddCell("Minute beyond package: " + receipt.MinutesBeyondPackageLimit); // "Row 8, Col 1" table.AddCell("price per minunte: " + receipt.PricePerMinute + "₪"); // "Row 8, Col 2" table.AddCell("Total: " + receipt.ExceptionalMinutesPrice); // "Row 8, Col 3" table.AddCell("SMS beyond package: " + receipt.SmsBeyondPackageLimit); // "Row 9, Col 1" table.AddCell("price per SMS: " + receipt.PricePerSms + "₪"); // "Row 9, Col 2" table.AddCell("Total: " + receipt.ExceptionalSmsPrice); // "Row 9, Col 3" //cell = new PdfPCell(new Phrase("Total:" + receipt.)); cell.Colspan = 3; cell.HorizontalAlignment = Element.ALIGN_CENTER; table.AddCell(cell); cell = new PdfPCell(new Phrase(" ")); cell.Colspan = 3; cell.HorizontalAlignment = Element.ALIGN_CENTER; table.AddCell(cell); return(table); }