Removed unused functions and documented reporting

This commit is contained in:
雲華
2022-04-17 13:19:35 -04:00
parent f6f90c76b2
commit 565997b9d7
5 changed files with 99 additions and 34 deletions

View File

@@ -5,6 +5,12 @@ namespace Ophelias.Reporting
{ {
internal static void GenerateAccommodationBills(List<Reservation> reservations) internal static void GenerateAccommodationBills(List<Reservation> reservations)
{ {
/*
* This function is used to format and create a new entry in the AccommodationBills.txt
* file. The accommodation bill details the guests Last, First name, the date they arrived,
* the date they depart/ departed, the length of their stay in days, and the amount they
* were charged.
*/
foreach (Reservation? r in reservations) foreach (Reservation? r in reservations)
{ {
string report = $"ACCOMMODATION BILL - GENERATED ON {DateTime.Now.Date.ToString("yyyy-MM-dd")}\n" + string report = $"ACCOMMODATION BILL - GENERATED ON {DateTime.Now.Date.ToString("yyyy-MM-dd")}\n" +

View File

@@ -2,6 +2,10 @@
{ {
internal class Email internal class Email
{ {
/*
* This is a simple email class to mimic what fields
* would exist if we were to send an email.
*/
private readonly string to; private readonly string to;
private readonly string subject = "Your payment is due soon!"; private readonly string subject = "Your payment is due soon!";
private readonly string body = "Hello valued customer, this is a reminder that your payment for your reservation is due soon, please login to the system and pay for your reservation. If you do not it will be canceled."; private readonly string body = "Hello valued customer, this is a reminder that your payment for your reservation is due soon, please login to the system and pay for your reservation. If you do not it will be canceled.";
@@ -13,6 +17,12 @@
} }
internal void Send() internal void Send()
{ {
/*
* Typically this function would send information or a built email
* to a mail server, however, since that was not in the design doc.
* a mockup was created to write what would go in the email to a
* text document.
*/
File.AppendAllText(Path.GetFullPath("Emails.txt"), File.AppendAllText(Path.GetFullPath("Emails.txt"),
$"TO: {to}\n" + $"TO: {to}\n" +
$"FROM: {from}\n" + $"FROM: {from}\n" +

View File

@@ -6,49 +6,68 @@ namespace Ophelias.Reporting
{ {
internal static class Management internal static class Management
{ {
/*
* The management class is a collection of functions used in management
* reporting. Specifically, the expected incomes, losses, and occupancy.
* All of these functions share similar functionality with different
* strings.
*/
internal static void CalculateExpectedOccupancy(List<(DateTime, int, int, int, int, int)> items, double average) internal static void CalculateExpectedOccupancy(List<(DateTime, int, int, int, int, int)> items, double average)
{ {
/*
* This function formats the data provided into a string that details the Date, Rooms Filled, # of Conventional,
* # of Prepaid, # of 60-day, and # of Incentive reservations. These are what the five ints are in the
* List items. The average is the calcualted average expected occupancy.
*/
List<string> entries = new(); List<string> entries = new();
foreach (var x in items) foreach (var x in items) // Build a list of entries
{ {
entries.Add($"{x.Item1.Date.ToString("yyyy-MM-dd")}\t{x.Item2}\t{x.Item3}\t{x.Item4}\t{x.Item5}\t{x.Item6}"); entries.Add($"{x.Item1.Date.ToString("yyyy-MM-dd")}\t{x.Item2}\t{x.Item3}\t{x.Item4}\t{x.Item5}\t{x.Item6}");
} }
string report = $"EXPECTED 30 DAY OCCUPANCY REPORT - GENERATED ON {DateTime.Now.Date.ToString("yyyy-MM-dd")}\n" + string report = $"EXPECTED 30 DAY OCCUPANCY REPORT - GENERATED ON {DateTime.Now.Date.ToString("yyyy-MM-dd")}\n" +
$"Date\tRooms Filled\tConventional\tPrepaid\t60-Day\tIncentive\n" + $"Date\tRooms Filled\tConventional\tPrepaid\t60-Day\tIncentive\n" +
$"{string.Join("\n", entries)}\n" + $"{string.Join("\n", entries)}\n" + // Combine entries at this location in the string
$"Average Occupancy Rate: {average}\n\n"; $"Average Occupancy Rate: {average}\n\n";
File.AppendAllText(Path.GetFullPath("ExpectedOccupancy.txt"), report); File.AppendAllText(Path.GetFullPath("ExpectedOccupancy.txt"), report); // Write to file
} }
internal static void CalculateExpectedIncome(List<(DateTime, double)> items, double totalIncome, double average) internal static void CalculateExpectedIncome(List<(DateTime, double)> items, double totalIncome, double average)
{ {
/*
* This function formats the expected income into a string with the details Date and Income as columns.
* The total income and average are appended after the columns as per the design doc.
*/
List<string> entries = new(); List<string> entries = new();
foreach (var x in items) foreach (var x in items) // Build a list of entries
{ {
entries.Add($"{x.Item1.Date.ToString("yyyy-MM-dd")}\t{x.Item2}"); entries.Add($"{x.Item1.Date.ToString("yyyy-MM-dd")}\t{x.Item2}");
} }
string report = $"EXPECTED 30 DAY INCOME REPORT - GENERATED ON {DateTime.Now.Date.ToString("yyyy-MM-dd")}\n" + string report = $"EXPECTED 30 DAY INCOME REPORT - GENERATED ON {DateTime.Now.Date.ToString("yyyy-MM-dd")}\n" +
$"Date\tIncome\n" + $"Date\tIncome\n" +
$"{string.Join("\n", entries)}\n" + $"{string.Join("\n", entries)}\n" + // Combine entries at this location in the string
$"Average Income: {average}\n" + $"Average Income: {average}\n" +
$"Total Income: {totalIncome}\n\n"; $"Total Income: {totalIncome}\n\n";
File.AppendAllText(Path.GetFullPath("ExpectedIncome.txt"), report); File.AppendAllText(Path.GetFullPath("ExpectedIncome.txt"), report); // Write to file
} }
internal static void CalculateIncentiveLosses(List<(DateTime, double)> items, double totalLosses, double average) internal static void CalculateIncentiveLosses(List<(DateTime, double)> items, double totalLosses, double average)
{ {
/*
* This function formats the expected income into a string with the details Date and Losses as columns.
* The total losses and average losses are appended after the columns as per the design doc.
*/
List<string> entries = new(); List<string> entries = new();
foreach (var x in items) foreach (var x in items) // Build a list of entries
{ {
entries.Add($"{x.Item1.Date.ToString("yyyy-MM-dd")}\t{x.Item2}"); entries.Add($"{x.Item1.Date.ToString("yyyy-MM-dd")}\t{x.Item2}");
} }
string report = $"EXPECTED 30 DAY LOSSES (TO INCENTIVE) REPORT - GENERATED ON {DateTime.Now.Date.ToString("yyyy-MM-dd")}\n" + string report = $"EXPECTED 30 DAY LOSSES (TO INCENTIVE) REPORT - GENERATED ON {DateTime.Now.Date.ToString("yyyy-MM-dd")}\n" +
$"Date\tLosses\n" + $"Date\tLosses\n" +
$"{string.Join("\n", entries)}\n" + $"{string.Join("\n", entries)}\n" + // Combine entries at this location in the string
$"Average Losses (Due to incentive): {average}\n" + $"Average Losses (Due to incentive): {average}\n" +
$"Total Losses (Due to incentive): {totalLosses}\n\n"; $"Total Losses (Due to incentive): {totalLosses}\n\n";
File.AppendAllText(Path.GetFullPath("IncentiveLosses.txt"), report); File.AppendAllText(Path.GetFullPath("IncentiveLosses.txt"), report); // Write to file
} }
} }
} }

View File

@@ -5,8 +5,23 @@ namespace Ophelias.Reporting
{ {
internal static class Operational internal static class Operational
{ {
/*
* This class is a collection of operational reporting operations.
* The purpose of it is to write out information regarding the daily
* arrivals and daily occupancy using fstring to print out the reports.
* The output is not fully formatted as there is no way to accurately pad
* the strings. If we knew the longest possible string, which we do not
* because names can be any length, we chose to use tabs for the initial
* spacing.
*/
internal static void FetchDailyArriavals(List<Reservation> reservations) internal static void FetchDailyArriavals(List<Reservation> reservations)
{ {
/*
* This class gets writes the daily arrivals in the reservation list.
* If there is a room number that is specified with an individual,
* their room number is listed. Otherwise it is marked as N/A since
* they have not checked in yet to recieve their room.
*/
List<string> entries = new(); List<string> entries = new();
foreach (Reservation r in reservations) foreach (Reservation r in reservations)
{ {
@@ -25,15 +40,25 @@ namespace Ophelias.Reporting
} }
string report = $"DAILY ARRIVAL REPORT - GENERATED ON {DateTime.Now.Date.ToString("yyyy-MM-dd")}\n" + string report = $"DAILY ARRIVAL REPORT - GENERATED ON {DateTime.Now.Date.ToString("yyyy-MM-dd")}\n" +
$"Last, First\tType\tRoom\tDeparture\n" + $"Last, First\tType\tRoom\tDeparture\n" +
$"{string.Join("\n", entries)}\n\n"; $"{string.Join("\n", entries)}\n\n"; // Format the list joined into the string
File.AppendAllText(Path.GetFullPath("DailyArrivals.txt"), report); File.AppendAllText(Path.GetFullPath("DailyArrivals.txt"), report); // Write to file
} }
internal static void FetchDailyOccupancy(List<(DateTime, int, string, string)> cop, List<int> pop) internal static void FetchDailyOccupancy(List<(DateTime, int, string, string)> cop, List<int> pop)
{ {
/*
* Fetch Daily Occupancy gets the occupancy for that day. If the guest is leaving
* the same day, an * will preceed their name. If the room they are in was occupied
* the day before, a last occupied date is included.
*/
List<string> entries = new(); List<string> entries = new();
foreach (var c in cop) foreach (var c in cop)
{ {
/*
* Iterates over each item to determine whether a date and *
* needs to be set based on the conditions detailed in the
* docstring.
*/
string lastOccupied; string lastOccupied;
string sameDayLeave = ""; string sameDayLeave = "";
if (pop.Contains(c.Item2)) if (pop.Contains(c.Item2))
@@ -53,9 +78,9 @@ namespace Ophelias.Reporting
string report = $"DAILY OCCUPANCY REPORT - GENERATED ON {DateTime.Now.Date.ToString("yyyy-MM-dd")}\n" + string report = $"DAILY OCCUPANCY REPORT - GENERATED ON {DateTime.Now.Date.ToString("yyyy-MM-dd")}\n" +
$"An * means that the guest is leaving the same day.\n" + $"An * means that the guest is leaving the same day.\n" +
$"Room #\tPrev. Occupied\tCurrent Occupant\n" + $"Room #\tPrev. Occupied\tCurrent Occupant\n" +
$"{string.Join("\n", entries)}\n\n"; $"{string.Join("\n", entries)}\n\n"; // Format the list joined into the string
File.AppendAllText(Path.GetFullPath("DailyOccupancy.txt"), report); File.AppendAllText(Path.GetFullPath("DailyOccupancy.txt"), report); // Write to file
} }
} }

View File

@@ -1,9 +1,4 @@
using System; using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.Globalization; using System.Globalization;
@@ -11,46 +6,56 @@ namespace Ophelias.Expressions
{ {
internal static class Expressions internal static class Expressions
{ {
/*
* These are a collection of regular expressions used in the validation class.
* They exist in their own class to better isolate them and make it easier to
* find.
*
* CardRx
* Regular expression to check for 16 digit credit cards
*
* ExpirationRx
* Ensures that a card expires sometime in past 2021
*
* CCVRx
* Checks to make sure the input is 3 digits
*
* MoneyRx
* Basic check to make sure money is in US format. 300.20/ 0.00 etc.
*/
internal static Regex CardRx = new(@"^[0-9]{16}$", RegexOptions.Compiled); internal static Regex CardRx = new(@"^[0-9]{16}$", RegexOptions.Compiled);
internal static Regex ExpriationRx = new(@"^(0?[1-9]|1[012])/2[0-9]{1}$", RegexOptions.Compiled); internal static Regex ExpriationRx = new(@"^(0?[1-9]|1[012])/[2-9][0-9]{1}$", RegexOptions.Compiled);
internal static Regex CCVRx = new(@"^[0-9]{3}$", RegexOptions.Compiled); internal static Regex CCVRx = new(@"^[0-9]{3}$", RegexOptions.Compiled);
internal static Regex MoneyRx = new(@"^(\d+\.\d{2}|\d+)$", RegexOptions.Compiled); internal static Regex MoneyRx = new(@"^(\d+\.\d{2}|\d+)$", RegexOptions.Compiled);
} }
internal static class Validation internal static class Validation
{ {
internal static bool ValidateCreditCard(string CreditCard) internal static bool ValidateCreditCard(string CreditCard) // Returns if the regex evaluates true or false
{ {
return Expressions.CardRx.IsMatch(CreditCard); return Expressions.CardRx.IsMatch(CreditCard);
} }
internal static bool ValidateExpirationDate(string Expiration) internal static bool ValidateExpirationDate(string Expiration) // Returns if the regex evaluates true or false
{ {
if (Expressions.ExpriationRx.IsMatch(Expiration)) if (Expressions.ExpriationRx.IsMatch(Expiration))
{ {
DateTime dt = DateTime.ParseExact(Expiration, "MM/yy", CultureInfo.InvariantCulture); DateTime dt = DateTime.ParseExact(Expiration, "MM/yy", CultureInfo.InvariantCulture); // Converts to date time for comparison
if (dt.Date >= DateTime.Now.Date) if (dt.Date >= DateTime.Now.Date)
return true; return true;
} }
return false; return false;
} }
internal static bool ValidateExpirationNotBeforeReservation(string Expiration, DateTime CollectionDate) internal static bool ValidateEmail(string email) // Returns if the regex evaluates true or false
{ {
DateTime dt = DateTime.ParseExact(Expiration, "MM/yy", CultureInfo.InvariantCulture); EmailAddressAttribute EmailChecker = new(); // Creates an email checker based off the EmailAddressAttribute class
if (dt.Date > CollectionDate.Date)
return true;
return false;
}
internal static bool ValidateEmail(string email)
{
EmailAddressAttribute EmailChecker = new();
return EmailChecker.IsValid(email); return EmailChecker.IsValid(email);
} }
internal static bool ValidateCCV(string CCV) internal static bool ValidateCCV(string CCV) // Returns if the regex evaluates true or false
{ {
if (Expressions.CCVRx.IsMatch(CCV)) if (Expressions.CCVRx.IsMatch(CCV))
return true; return true;
return false; return false;
} }
internal static bool ValidateMoney(string Money) internal static bool ValidateMoney(string Money) // Returns if the regex evaluates true or false
{ {
return Expressions.MoneyRx.IsMatch(Money); return Expressions.MoneyRx.IsMatch(Money);
} }