This commit versions the inital classes used for reporting. Some of the manager classes have been adjusted so that they can also be used in the reporting system since the queries are very similar. The terminal commands and flow have been improved to further close in on the design spec. Guests who make reservations now abide by the fixed rules determined by the doc. For example Prepaid and 60 day reservations have requirements on how far away a reservation needs to be at minimum. The reservation creation process now takes this into account. The base rate functionality has been hooked up and the queries have been verified to work at least once. The same applies for CheckIn() and CheckOut() functions.
186 lines
8.2 KiB
C#
186 lines
8.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
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 = HotelManager.GetBaseRate();
|
|
if (BaseRate == null) {
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
Transaction Transaction = new Transaction(
|
|
Rate: (double)BaseRate,
|
|
Owed: TxFunctions.CalculateOwed((double)BaseRate, (int)(EndDate.Date - StartDate.Date).TotalDays, Multiplier),
|
|
Multiplier: Multiplier,
|
|
PayBy: TxFunctions.GetPayByDate(Type, StartDate, EndDate)
|
|
);
|
|
using (DatabaseManager Manager = new DatabaseManager())
|
|
{
|
|
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 (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);
|
|
|
|
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 = HotelManager.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 (DatabaseManager Manager = new DatabaseManager())
|
|
{
|
|
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,
|
|
}
|
|
}
|