From 0ce34d9d2352e18ac7c03d4ec906d3c3f132497e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B2=E8=8F=AF?= <42814579+yunwah@users.noreply.github.com> Date: Sun, 17 Apr 2022 17:44:41 -0400 Subject: [PATCH] Fixed an incorrect calulation The calculations used in the reports were calulating based off the owed column which mathematically did not make sense since we are looking for the daily. --- OpheliasOasis/Managers/Hotel.cs | 4 ++-- OpheliasOasis/Program.cs | 19 +++++++++++++++---- OpheliasOasis/Validation.cs | 2 +- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/OpheliasOasis/Managers/Hotel.cs b/OpheliasOasis/Managers/Hotel.cs index 9446d51..2f0fe26 100644 --- a/OpheliasOasis/Managers/Hotel.cs +++ b/OpheliasOasis/Managers/Hotel.cs @@ -190,7 +190,7 @@ namespace Ophelias.Managers { using (SQLiteCommand cmd = Manager.con.CreateCommand()) // Create a new command to execute { - cmd.CommandText = "SELECT sum(((julianday(EndDate) - julianday(StartDate)) * transactions.Rate) - transactions.Owed) AS Loss " + + cmd.CommandText = "SELECT sum(transactions.Rate - (transactions.Rate * transactions.Multiplier)) AS Loss " + "FROM reservations " + "INNER JOIN transactions ON reservations.TransactionID = transactions.ID " + "WHERE (DATE(@Date) BETWEEN StartDate AND EndDate) AND STATUS IN (@Status1,@Status2) AND Type = @Type"; @@ -234,7 +234,7 @@ namespace Ophelias.Managers { using (SQLiteCommand cmd = Manager.con.CreateCommand()) // Create a new command to execute { - cmd.CommandText = "SELECT sum(transactions.Owed) FROM reservations " + + cmd.CommandText = "SELECT sum(transactions.Rate * Multiplier) FROM reservations " + "INNER JOIN transactions ON reservations.TransactionID = transactions.ID " + "WHERE (DATE(@Date) BETWEEN StartDate AND EndDate) AND Status IN (@Status1,@Status2);"; cmd.Parameters.AddWithValue("@Date", dt.AddDays(i).Date.ToString("yyyy-MM-dd")); diff --git a/OpheliasOasis/Program.cs b/OpheliasOasis/Program.cs index 1ffda62..d8928e8 100644 --- a/OpheliasOasis/Program.cs +++ b/OpheliasOasis/Program.cs @@ -182,8 +182,16 @@ internal class Program * has been split into other functions. See those functions for details on how * they work. */ + activeReservation = null; + activeGuest = null; (string FirstName, string LastName) = GetGuestName(); string Email = GetGuestEmail(); + activeGuest = Hotel.GetGuestByEmail(Email); + if (activeGuest != null) + { + Console.WriteLine($"\nThere is already a guest with the email {Email}."); + return; + } Console.Write("Would you like to enter your credit card details? (Y/n): "); string? CreditCard = null; string? CardExpiration = null; @@ -347,6 +355,7 @@ internal class Program if ((int)(Date - DateTime.Now).TotalDays < 90) { Console.WriteLine("Prepaid reservations must be made 90 days in advance."); + return false; } else { @@ -358,13 +367,14 @@ internal class Program if ((int)(Date - DateTime.Now).TotalDays < 60) { Console.WriteLine("Sixty-days-in-advance reservations must be made 60 days in advance."); + return false; } else { return true; } } - return false; + return true; } (DateTime?, DateTime?) SelectDate(ReservationType Type) { @@ -497,7 +507,7 @@ internal class Program Console.WriteLine("Aborting reservation creation."); return; } - + string? cc, exp, ccv; while ((Type != ReservationType.SixtyDayAdvance && (activeGuest.CreditCard == null || activeGuest.Expiration == null || activeGuest.CCV == null))) { @@ -509,8 +519,9 @@ internal class Program { return; } - - GetCreditCardInformation(); + (cc,exp,ccv) = GetCreditCardInformation(); + if (cc != null && exp != null && ccv != null) + activeGuest.UpdateGuest(activeGuest.Id, CreditCard: cc, Expiration: exp, CCV: ccv); } Console.Write($"Thank you for filling out your reservation details. Currently you have made a {Type} " + diff --git a/OpheliasOasis/Validation.cs b/OpheliasOasis/Validation.cs index 32e7c24..607a2d6 100644 --- a/OpheliasOasis/Validation.cs +++ b/OpheliasOasis/Validation.cs @@ -24,7 +24,7 @@ namespace Ophelias.Expressions * 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 ExpriationRx = new(@"^(0?[1-9]|1[012])/[2-9][0-9]{1}$", RegexOptions.Compiled); + internal static Regex ExpriationRx = new(@"^(0?[1-9]|1[012])/2[0-9]{1}$", RegexOptions.Compiled); internal static Regex CCVRx = new(@"^[0-9]{3}$", RegexOptions.Compiled); internal static Regex MoneyRx = new(@"^(\d+\.\d{2}|\d+)$", RegexOptions.Compiled); }