Files
ophelias-oasis/OpheliasOasis/Models/Reservation.cs
雲華 fbb75a583d First major version of the project
This finishes the first iteration of the project. Reports have been
tested and are functional in terms of writing out and outputting some
form of text. There are still a few bugs here and there that are found
but ultimately this commit is so testing can begin.

Since the changes are too large to individually summarize, here is the
generalization:

Reports have been integrated into the admin mode. They write out to text
files rather than export to say email or a printer as it was not to be
considered for this version. The files are appended too and exist in the
debug director of the project. I made this easier to find by outputting
where the files were output to after running the report.

Other changes included some bug fixes, optimizations, and a few bit of
automatic cleanup. This may lead to sylistic inconsistencies.

Documentation will come in a later commit.
2022-04-16 04:42:13 -04:00

208 lines
8.5 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();
}
}
}
}
internal enum ReservationStatus
{
Active,
Changed,
Cancelled,
Ended,
}
internal enum ReservationType
{
Conventional,
Prepaid,
SixtyDayAdvance,
Incentive,
}
}