IO format fixes and implemented res payment

This is a small commit to include the feature for paying for a
reservation, specifically only the 60-day-in-advance reservation type as
the others are paid for at specific periods. Other fixes include just
some formatting for reports.
This commit is contained in:
雲華
2022-04-16 13:59:27 -04:00
parent f75a384d0a
commit 989a4dd65c
5 changed files with 146 additions and 15 deletions

View File

@@ -265,7 +265,7 @@ namespace Ophelias.Managers
if (!string.IsNullOrEmpty(CreditCard))
{
QueryParts.Add($"CreditCard = @CC");
QueryParts.Add($"CreditCard = @CreditCard");
}
if (!string.IsNullOrEmpty(Expiration))

View File

@@ -67,6 +67,12 @@ namespace Ophelias.Models
{
using SQLiteCommand cmd = Manager.con.CreateCommand();
cmd.CommandText = QueryBuilder.UpdateGuest(Id, FirstName, LastName, Email, CreditCard, Expiration, CCV);
cmd.Parameters.AddWithValue("@Fname", FirstName);
cmd.Parameters.AddWithValue("@Lname", LastName);
cmd.Parameters.AddWithValue("@Email", Email);
cmd.Parameters.AddWithValue("@CreditCard", CreditCard);
cmd.Parameters.AddWithValue("@Expiry", Expiration);
cmd.Parameters.AddWithValue("@CCV", CCV);
cmd.ExecuteNonQuery();
}
if (FirstName != null)

View File

@@ -107,11 +107,19 @@ namespace Ophelias.Models
cmd.Parameters.AddWithValue("@PayBy", this.PayBy.ToString("yyyy-MM-dd"));
cmd.ExecuteNonQuery();
}
internal void Pay(double Amount)
internal PaymentStatus Pay(double Amount, string cc)
{
if (string.IsNullOrEmpty(cc))
{
return PaymentStatus.MissingCreditCard;
}
if (Amount >= Owed)
{
return PaymentStatus.AlreadyPaid;
}
if (Amount <= 0)
{
return;
return PaymentStatus.AmountCannotZero;
}
LastPaid = DateTime.Now;
@@ -144,6 +152,7 @@ namespace Ophelias.Models
throw new Exception();
cmd.Parameters.AddWithValue("@PaidOn", PaidOn.Value.ToString("yyyy-MM-dd"));
cmd.ExecuteNonQuery();
return PaymentStatus.SuccessfulPayment;
}
internal void Refund()
{
@@ -200,13 +209,12 @@ namespace Ophelias.Models
}
internal class TransactionList
internal enum PaymentStatus
{
internal List<Transaction> Transactions;
internal TransactionList()
{
Transactions = new();
}
SuccessfulPayment,
AlreadyPaid,
FailedPayment,
AmountCannotZero,
MissingCreditCard
}
}

View File

@@ -32,11 +32,12 @@ internal class Program
"\treservation create - Create a new reservation.\n" +
"\treservation update - Update your active reservation.\n" +
"\treservation cancel - Cancel a reservation.\n" +
"\treservation pay - Pays in full for an active reservation.\n" +
"Account Commands:\n" +
"\taccount create - Create a new guest account.\n" +
"\taccount update - Update your account information.\n" +
"\taccount login - Log into your guest account." +
"Enter Q to quit.\n"
"Enter Q or q to quit.\n"
);
return;
}
@@ -220,6 +221,7 @@ internal class Program
Console.WriteLine($"The following changes have been made:\n {changes}");
activeGuest.UpdateGuest(activeGuest.Id, NewFname, NewLname, NewEmail, NewCard, NewExpiry, NewCCV);
activeReservation.Guest = activeGuest;
return;
}
@@ -491,7 +493,7 @@ internal class Program
if (Type == ReservationType.Prepaid)
{
activeReservation = new(activeGuest, Type, DateTime.Now.Date, StartDate.Value, EndDate.Value);
activeReservation.Transaction.Pay(activeReservation.Transaction.Owed);
activeReservation.Transaction.Pay(activeReservation.Transaction.Owed, activeGuest.CreditCard);
}
else
{
@@ -586,6 +588,118 @@ internal class Program
activeReservation = null;
Console.Write("Reservation has been cancelled, you may be charged based on your reservation.");
}
void PayForReservation()
{
if (activeGuest == null)
{
Console.WriteLine("No guest is currently logged in, please login.");
return;
}
if (activeReservation == null)
{
Console.WriteLine("You currently do not have an active registration.");
return;
}
if (ReservationType.Incentive == activeReservation.Type)
{
Console.WriteLine("Incentive reservations are paid for when you check-out.");
return;
}
else if (ReservationType.Conventional == activeReservation.Type)
{
Console.WriteLine("Conventional reservations are paid for when you check-out.");
return;
}
else if (ReservationType.Prepaid == activeReservation.Type)
{
Console.WriteLine("Prepaid reservations are paid for when you create them.");
return;
} else if (ReservationType.SixtyDayAdvance == activeReservation.Type)
{
if(activeReservation.StartDate.AddDays(-30).Date < DateTime.Now.Date)
{
if (activeReservation.Transaction.Owed <= activeReservation.Transaction.AmountPaid)
{
Console.WriteLine("Your reservation has already been paid for.");
return;
}
activeReservation.CancelReservation();
Console.WriteLine("Your reservation has been cancelled because you failed to pay within the payment period.");
return;
}
}
string? cc, exp, ccv;
cc = activeGuest.CreditCard;
exp = activeGuest.Expiration;
ccv = activeGuest.CCV;
while (true)
{
if (cc == null || exp == null || ccv == null)
(cc, exp, ccv) = GetCreditCardInformation();
if (cc == null || exp == null || ccv == null)
{
Console.Write("Would you like to try again and enter your payment information? (Your reservation will not be canceled)\n" +
"YES or NO: ");
while (true)
{
string input = Console.ReadLine();
if (input == "YES")
{
break;
} else if (input == "NO")
{
Console.WriteLine("Payment has been aborted.");
return;
}
else
{
Console.WriteLine("Input must be YES or NO.");
}
}
} else if (cc != null && exp != null && ccv != null)
{
if (ReservationType.SixtyDayAdvance == activeReservation.Type && ((DateTime.Parse(exp).Date < activeReservation.StartDate.AddDays(-30).Date) && (DateTime.Parse(exp).Date < activeReservation.StartDate.AddDays(-45).Date)))
{
Console.WriteLine("Your card expires too soon. Please enter the correct expiration date if incorrect or a new card.");
cc = null;
exp = null;
ccv = null;
}
else if (ReservationType.SixtyDayAdvance == activeReservation.Type && ((DateTime.Parse(exp).Date > activeReservation.StartDate.AddDays(-30).Date) && (DateTime.Parse(exp).Date > activeReservation.StartDate.AddDays(-45).Date)))
{
if (cc != activeGuest.CreditCard && exp != activeGuest.Expiration && ccv != activeGuest.CCV)
{
activeGuest.UpdateGuest(activeGuest.Id, CreditCard: cc, Expiration: exp, CCV: ccv);
activeReservation.Guest = activeGuest;
}
PaymentStatus ps = activeReservation.Transaction.Pay(activeReservation.Transaction.Owed, activeGuest.CreditCard);
if (ps == PaymentStatus.SuccessfulPayment)
{
Console.WriteLine("Your reservation has been paid for.");
return;
} else if (ps == PaymentStatus.FailedPayment)
{
Console.WriteLine("There was an error paying for your resevation. Try again later or contact the Ophelias Oasis team.");
return;
} else if (ps == PaymentStatus.AmountCannotZero)
{
Console.WriteLine("You cannot pay $0 or less than $0.");
return;
} else if (ps == PaymentStatus.MissingCreditCard)
{
Console.WriteLine("Credit Card information is missing. Payment could not be made.");
} else if (ps == PaymentStatus.AlreadyPaid)
{
Console.WriteLine("Your reservation has already been paid for.");
return;
}
}
}
}
}
Console.Write(
"\nWelcome to the Ophelias Oasis Hotel Registration System!\n" +
"Type help to get a full list of commands or enter a command.\n" +
@@ -601,10 +715,12 @@ internal class Program
case "reservation create": CreateNewReservation(); break;
case "reservation update": UpdateReservation(); break;
case "reservation cancel": CancelReservation(); break;
case "reservation pay": PayForReservation(); break;
case "account create": CreateNewGuestPrompt(); break;
case "account update": UpdateGuestInformation(); break;
case "account login": GuestLogin(); break;
case "q": return;
case "Q": return;
default: Console.WriteLine("Unknown command, enter help for more inforamtion."); break;
}
Console.Write("\nCommand: ");
@@ -626,7 +742,7 @@ internal class Program
"\tcheckin guest - Checks in a guest and assigns them a room.\n" +
"\tcheckout guest - Checks out a guest and removes their room assignment.\n" +
"\tset rate - Sets a new base rate to begin after a specified date.\n" +
"Enter Q to quit.\n"
"Enter Q or q to quit.\n"
);
return;
}
@@ -791,7 +907,7 @@ internal class Program
Reservation r = Hotel.GetResByGuest(Hotel.GetGuestByEmail(Email));
if (r.Type == ReservationType.Incentive || r.Type == ReservationType.Conventional)
{
r.Transaction.Pay(r.Transaction.Owed);
r.Transaction.Pay(r.Transaction.Owed, r.Guest.CreditCard);
}
Hotel.CheckOutGuest(Email, DateTime.Now.Date);
@@ -898,6 +1014,7 @@ internal class Program
case "checkout guest": CheckOut(); break;
case "set rate": SetFutureBaseRate(); break;
case "Q": return;
case "q": return;
default: Console.WriteLine("Unknown command, enter help for more inforamtion."); break;
}
Console.Write("\nCommand: ");

View File

@@ -24,7 +24,7 @@ namespace Ophelias.Reporting
entries.Add($"{r.Guest.LastName}, {r.Guest.FirstName}\t{r.Type}\t{roominfo}\t{r.EndDate}");
}
string report = $"DAILY ARRIVAL REPORT - GENERATED ON {DateTime.Now.Date.ToString("yyyy-MM-dd")}\n" +
$"Last, First\tType\tRoom\tDeparture" +
$"Last, First\tType\tRoom\tDeparture\n" +
$"{string.Join("\n", entries)}\n\n";
File.AppendAllText(Path.GetFullPath("DailyArrivals.txt"), report);