Files
ophelias-oasis/OpheliasOasis/Models/Reservation.cs
雲華 972a968994 Added issue penalties function
This commit adds another piece of functinality allowing the staff to
issue penalties. This currently just charges users for their owed amount
and there are no actual penalty fees. The design document did not call
for that. There is also some documentation that was written. The next
several set of commits are likely to be documentation.
2022-04-16 15:28:06 -04:00

218 lines
9.0 KiB
C#

using Ophelias.Managers;
using System.Data.SQLite;
namespace Ophelias.Models
{
internal class Reservation
{
internal int Id;
internal int? RoomNum;
internal Guest Guest;
internal Transaction Transaction;
internal bool IsNoShow;
internal ReservationType Type;
internal ReservationStatus Status;
internal DateTime CreationDate;
internal DateTime StartDate;
internal DateTime EndDate;
internal DateTime? CheckIn;
internal DateTime? CheckOut;
internal DateTime? DateChanged;
internal Reservation(Guest Guest, ReservationType Type,
DateTime CreationDate, DateTime StartDate, DateTime EndDate, ReservationStatus Status = ReservationStatus.Active,
bool IsNoShow = false, DateTime? CheckIn = null, DateTime? CheckOut = null, DateTime? DateChanged = null, int? RoomNum = null)
{
int Id; double Multiplier;
switch (Type)
{
case ReservationType.Conventional: Multiplier = TxFunctions.ConventionalFee; break;
case ReservationType.Prepaid: Multiplier = TxFunctions.PrepaidFee; break;
case ReservationType.Incentive: Multiplier = TxFunctions.IncentiveFee(StartDate, EndDate); break;
case ReservationType.SixtyDayAdvance: Multiplier = TxFunctions.SixtyDayFee; break;
default: throw new NotImplementedException();
}
double? BaseRate = Hotel.GetBaseRate();
if (BaseRate == null)
{
throw new NotImplementedException();
}
Transaction Transaction = new(
Rate: (double)BaseRate,
Owed: TxFunctions.CalculateOwed((double)BaseRate, (int)(EndDate.Date - StartDate.Date).TotalDays, Multiplier),
Multiplier: Multiplier,
PayBy: TxFunctions.GetPayByDate(Type, StartDate, EndDate)
);
using (Database Manager = new())
{
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
if (RoomNum != null)
{
this.RoomNum = RoomNum;
}
cmd.CommandText =
"INSERT INTO reservations (RoomNum, GuestID, TransactionID, IsNoShow, Type, Status, CreationDate, StartDate, EndDate, CheckIn, CheckOut, DateChanged) " +
"VALUES (@RoomNum, @GuestID, @TransactionID, @IsNoShow, @Type, @Status, @CreationDate, @StartDate, @EndDate, @CheckIn, @CheckOut, @DateChanged);";
cmd.Parameters.AddWithValue("@RoomNum", RoomNum);
cmd.Parameters.AddWithValue("@GuestID", Guest.Id);
cmd.Parameters.AddWithValue("@TransactionID", Transaction.Id);
cmd.Parameters.AddWithValue("@IsNoShow", Convert.ToInt32(IsNoShow));
cmd.Parameters.AddWithValue("@Type", (int)Type);
cmd.Parameters.AddWithValue("@Status", (int)Status);
cmd.Parameters.AddWithValue("@CreationDate", CreationDate.ToString("yyyy-MM-dd"));
cmd.Parameters.AddWithValue("@StartDate", StartDate.ToString("yyyy-MM-dd"));
cmd.Parameters.AddWithValue("@EndDate", EndDate.ToString("yyyy-MM-dd"));
if (CheckIn.HasValue)
{
cmd.Parameters.AddWithValue("@CheckIn", CheckIn.Value.ToString("yyyy-MM-dd"));
}
else
{
cmd.Parameters.AddWithValue("@CheckIn", CheckIn);
}
if (CheckOut.HasValue)
{
cmd.Parameters.AddWithValue("@CheckOut", CheckOut.Value.ToString("yyyy-MM-dd"));
}
else
{
cmd.Parameters.AddWithValue("@CheckOut", CheckOut);
}
if (DateChanged.HasValue)
{
cmd.Parameters.AddWithValue("@DateChanged", DateChanged.Value.ToString("yyyy-MM-dd"));
}
else
{
cmd.Parameters.AddWithValue("@DateChanged", DateChanged);
}
cmd.ExecuteNonQuery();
}
Id = (int)Manager.con.LastInsertRowId;
}
this.Id = Id;
this.RoomNum = RoomNum;
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 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, int? RoomNum = null)
{
this.Id = Id;
this.RoomNum = RoomNum;
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 (Database Manager = new())
{
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
string? query = QueryBuilder.UpdateReservation(Id: Id, Status: ReservationStatus.Changed, StartDate: this.StartDate, EndDate: this.EndDate, DateChanged: DateChanged);
if (query == null)
{
throw new Exception();
}
cmd.CommandText = query;
cmd.Parameters.AddWithValue("@ID", Id);
cmd.Parameters.AddWithValue("@Status", Status);
cmd.Parameters.AddWithValue("@StartDate", StartDate.ToString("yyyy-MM-dd"));
cmd.Parameters.AddWithValue("@EndDate", EndDate.ToString("yyyy-MM-dd"));
cmd.Parameters.AddWithValue("@DateChanged", DateChanged.Value.ToString("yyyy-MM-dd"));
cmd.ExecuteNonQuery();
}
}
double? BaseRate = Hotel.GetBaseRate();
if (BaseRate == null)
{
throw new ArgumentNullException(nameof(BaseRate));
}
Transaction.UpdateTransactionFees((double)BaseRate, TxFunctions.Changed, TxFunctions.GetPayByDate(Type, this.StartDate, this.EndDate));
}
internal void CancelReservation()
{
DateTime _DateChanged = DateTime.Now.Date;
using (Database Manager = new())
{
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
string? query = QueryBuilder.UpdateReservation(Id: Id, Status: ReservationStatus.Cancelled, DateChanged: _DateChanged);
if (query == null)
{
throw new Exception();
}
Status = ReservationStatus.Cancelled;
DateChanged = _DateChanged;
cmd.CommandText = query;
cmd.Parameters.AddWithValue("@ID", Id);
cmd.Parameters.AddWithValue("@Status", Status);
cmd.Parameters.AddWithValue("@DateChanged", DateChanged.Value.ToString("yyyy-MM-dd"));
cmd.ExecuteNonQuery();
}
}
if (Type == ReservationType.Conventional && _DateChanged.Date >= StartDate.AddDays(-3).Date)
{
Transaction.Pay(Transaction.Owed, Guest.CreditCard);
} else if (Type == ReservationType.Incentive && _DateChanged.Date >= StartDate.AddDays(-3).Date)
{
Transaction.Pay(Transaction.Owed, Guest.CreditCard);
} else if (_DateChanged.Date > StartDate.Date)
{
Transaction.Pay(Transaction.Owed, Guest.CreditCard);
}
}
}
internal enum ReservationStatus
{
Active,
Changed,
Cancelled,
Ended,
}
internal enum ReservationType
{
Conventional,
Prepaid,
SixtyDayAdvance,
Incentive,
}
}