Begun integration of models and managers

The HotelManager class now has been connected to some aspects of the
command line interface and is functioning for a few cases such as
logging in as a specific guest via email, chaging a guests information
and creating a new guest account. This was implemented first over the
reservation system to test and implement something on a smaller scale.
Furthermore, the reservation depends on an existing guest account since
a Guest ID needs to be linked to the reservation that is created.
Other changes include redesigning, tweaking/ adjusting, and/ or fixing
of other modules that have not yet been implemented or are partially
implemented.
This commit is contained in:
雲華
2022-04-13 23:53:17 -04:00
parent 306ac411b3
commit 8764c2e57c
7 changed files with 673 additions and 281 deletions

View File

@@ -17,14 +17,9 @@ namespace Ophelias.Models
internal string? CCV;
internal string? Expiration;
internal Guest(string FirstName, string LastName, string Email)
{
this.FirstName = FirstName;
this.LastName = LastName;
this.Email = Email;
}
internal Guest(string FirstName, string LastName, string Email, string CreditCard, string Expiration, string CCV)
internal Guest(int Id, string FirstName, string LastName, string Email, string? CreditCard = null, string? Expiration = null, string? CCV = null)
{
this.Id = Id;
this.FirstName = FirstName;
this.LastName = LastName;
this.Email = Email;

View File

@@ -1,19 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Ophelias.Models;
using Ophelias.Managers;
using System.Data.SQLite;
namespace Ophelias.Models
{
internal class Reservation
{
internal int Id;
internal int RoomId;
internal int GuestId;
internal int TransactionId;
internal Room Room;
internal Guest Guest;
internal Transaction Transaction;
internal bool IsNoShow;
@@ -28,26 +26,57 @@ namespace Ophelias.Models
internal DateTime? CheckOut;
internal DateTime? DateChanged;
internal Reservation(int id, int gid, int tid, int room, ReservationType type, ReservationStatus status,
DateTime startdate, DateTime enddate)
internal Reservation(int Id, Guest Guest, Transaction Transaction, ReservationType Type, ReservationStatus Status,
DateTime CreationDate, DateTime StartDate, DateTime EndDate, bool IsNoShow = false, DateTime? CheckIn = null, DateTime? CheckOut = null, DateTime? DateChanged = null)
{
Id = id;
RoomId = room;
GuestId = gid;
TransactionId = tid;
this.Id = Id;
this.Guest = Guest;
this.Transaction = Transaction;
this.IsNoShow = IsNoShow;
this.Type = Type;
this.Status = Status;
this.CreationDate = CreationDate;
this.StartDate = StartDate;
this.EndDate = EndDate;
this.CheckIn = CheckIn;
this.CheckOut = CheckOut;
this.DateChanged = DateChanged;
}
internal void ChangeReservationDates(DateTime StartDate, DateTime EndDate)
{
this.StartDate = StartDate;
this.EndDate = EndDate;
DateChanged = DateTime.Now.Date;
using (DatabaseManager Manager = new DatabaseManager())
{
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
string? query = QueryBuilder.UpdateReservation(Id: Id, Status: ReservationStatus.Changed, StartDate: this.StartDate, EndDate: this.EndDate, DateChanged: DateChanged);
IsNoShow = false;
if (query == null)
throw new Exception();
Type = type;
Status = status;
cmd.CommandText = query;
cmd.ExecuteNonQuery();
}
}
Transaction.UpdateTransactionFees(HotelManager.GetBaseRate(), TxFunctions.Changed, TxFunctions.GetPayByDate(Type, this.StartDate, this.EndDate));
}
internal void CancelReservation()
{
using (DatabaseManager Manager = new DatabaseManager())
{
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
string? query = QueryBuilder.UpdateReservation(Id: Id, Status: ReservationStatus.Cancelled, DateChanged: DateTime.Now.Date);
CreationDate = DateTime.Now;
StartDate = startdate;
EndDate = enddate;
if (query == null)
throw new Exception();
CheckIn = null;
CheckOut = null;
DateChanged = null;
cmd.CommandText = query;
cmd.ExecuteNonQuery();
}
}
}
}
internal enum ReservationStatus

View File

@@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OpheliasOasis.Models
namespace Ophelias.Models
{
internal class Room
{

View File

@@ -5,13 +5,12 @@ using System.Text;
using System.Threading.Tasks;
using Ophelias.Models;
using Ophelias.Managers;
using System.Data.SQLite;
namespace Ophelias.Models
{
internal class Transaction
{
private double PenaltyMultipler = 1.1;
internal int Id { get; set; }
internal double Rate { get; set; }
internal double Owed { get; set; }
@@ -19,11 +18,12 @@ namespace Ophelias.Models
internal double Multiplier { get; set; }
internal double RefundAmount { get; set; }
internal DateTime PayBy { get; set; }
internal DateTime? LastPaid { get; set; } = null;
internal DateTime? PaidOn { get; set; } = null;
internal Transaction(int Id, double Rate, double Owed, double Penalty,
double Multiplier, double RefundAmount,
DateTime PayBy, DateTime? PaidOn = null)
internal Transaction(int Id, double Rate, double Owed,
double Multiplier, DateTime PayBy, DateTime? LastPaid = null,
DateTime? PaidOn = null, double RefundAmount = 0, double Penalty = 0)
{
this.Id = Id;
this.Rate = Rate;
@@ -32,79 +32,102 @@ namespace Ophelias.Models
this.Multiplier = Multiplier;
this.RefundAmount = RefundAmount;
this.PayBy = PayBy;
this.LastPaid = LastPaid;
this.PaidOn = PaidOn;
}
private void Cancellation(ReservationType type)
internal void UpdateTransactionFees(double Rate, double Multiplier, DateTime PayBy)
{
void SetRefund()
this.Rate = Rate;
this.Multiplier = Multiplier;
this.PayBy = PayBy;
using (DatabaseManager Manager = new DatabaseManager())
{
if (DateTime.Now.AddDays(+3).Day <= PayBy.Day)
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
RefundAmount = Paid;
Paid = 0;
Owed = 0;
PaidOff = false;
string? query = QueryBuilder.UpdateTransaction(Id: Id, Rate: this.Rate, Multiplier: this.Multiplier, PayBy: this.PayBy);
if (query == null)
throw new Exception();
cmd.CommandText = query;
cmd.ExecuteNonQuery();
}
}
switch (type)
}
internal void Pay(double Amount)
{
if (Amount <= 0)
return;
LastPaid = DateTime.Now;
Owed -= Amount;
if (Owed < 0)
RefundAmount = Math.Abs(Owed);
else if (Owed == 0)
PaidOn = DateTime.Now;
using (DatabaseManager Manager = new DatabaseManager())
{
case ReservationType.Conventional: SetRefund(); return;
case ReservationType.Prepaid: return;
case ReservationType.Incentive: SetRefund(); return;
case ReservationType.SixtyDayAdvance: return;
default: throw new NotImplementedException();
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
string? query = QueryBuilder.UpdateTransaction(Id: Id, Owed: Owed, Refund: RefundAmount, LastPaid: LastPaid, PaidOn: PaidOn);
if (query == null)
throw new Exception();
cmd.CommandText = query;
cmd.ExecuteNonQuery();
}
}
}
internal void Penalize(Reservation r)
internal void Refund()
{
switch (r.Status)
RefundAmount = 0;
using (DatabaseManager Manager = new DatabaseManager())
{
case ReservationStatus.Active: IsOverdue(); return;
case ReservationStatus.Ended: IsOverdue(); return;
case ReservationStatus.Cancelled: CancellationHandler(r.Type); return;
default: throw new NotImplementedException();
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
string? query = QueryBuilder.UpdateTransaction(Id: Id, Refund: RefundAmount);
if (query == null)
throw new Exception();
cmd.CommandText = query;
cmd.ExecuteNonQuery();
}
}
}
internal void Penalize(Reservation r, double rate)
{
throw new NotImplementedException();
}
internal void Pay(double amount)
{
}
}
internal static class TransactionInfo
internal static class TxFunctions
{
internal static double ConventionalFee = 1.0;
internal static double PrepaidFee = 0.75;
internal static double IncentiveFee = IncentiveRate();
internal static double SixtyDayFee = 0.85;
private static double IncentiveRate()
internal static double Changed = 1.1;
internal static double IncentiveFee(DateTime Start, DateTime End)
{
int thirtyDayOcc;
thirtyDayOcc = HotelManager.GetThirtyDayOccupancy(DateTime.Now);
thirtyDayOcc = HotelManager.AvgOccupancySpan(Start, End);
if ((double)(thirtyDayOcc / 45.0) <= 0.6)
return 0.80;
return 1.0;
}
internal static DateTime GetPayByDate(Reservation r)
internal static DateTime GetPayByDate(ReservationType Type, DateTime StartDate, DateTime EndDate)
{
switch (r.Type)
switch (Type)
{
case ReservationType.Conventional: return r.EndDate;
case ReservationType.Prepaid: return r.StartDate;
case ReservationType.Incentive: return r.EndDate;
case ReservationType.SixtyDayAdvance: return r.StartDate.AddDays(-30);
case ReservationType.Conventional: return EndDate;
case ReservationType.Prepaid: return StartDate;
case ReservationType.Incentive: return EndDate;
case ReservationType.SixtyDayAdvance: return StartDate.AddDays(-30);
default: throw new NotImplementedException();
}
}
internal static double CalculateOwed(double Rate, int Days)
{
return Rate * (double)Days;
}
}
internal class TransactionList