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.
962 lines
47 KiB
C#
962 lines
47 KiB
C#
using Ophelias.Models;
|
|
using System.Data.SQLite;
|
|
|
|
namespace Ophelias.Managers
|
|
{
|
|
internal static class Hotel
|
|
{
|
|
internal static int GetLastId(string tableName)
|
|
{
|
|
int LastId = 0;
|
|
using (Database Manager = new())
|
|
{
|
|
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
|
{
|
|
cmd.CommandText = $"SELECT SEQ FROM sqlite_sequence WHERE name=@Table;";
|
|
cmd.ExecuteNonQuery();
|
|
cmd.Parameters.AddWithValue("@Table", tableName);
|
|
using SQLiteDataReader reader = cmd.ExecuteReader();
|
|
reader.Read();
|
|
if (reader.HasRows && !reader.IsDBNull(0))
|
|
{
|
|
LastId = reader.GetInt32(0);
|
|
}
|
|
}
|
|
}
|
|
return LastId;
|
|
}
|
|
internal static (List<(DateTime, int, string, string)>, List<int>) GetDailyOccupancy()
|
|
{
|
|
List<int> previousOccupancies = new();
|
|
List<(DateTime, int, string, string)> currentOccupancies = new();
|
|
using (Database Manager = new())
|
|
{
|
|
using SQLiteTransaction Transaction = Manager.con.BeginTransaction();
|
|
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
|
{
|
|
cmd.CommandText = "SELECT RoomNum, Lname, Fname, EndDate FROM reservations " +
|
|
"INNER JOIN guests ON reservations.GuestID = guests.ID " +
|
|
"INNER JOIN rooms ON reservations.RoomNum = rooms.ID " +
|
|
"WHERE (DATE(@Date) BETWEEN StartDate AND EndDate) AND Status IN (@Status1,@Status2) AND CheckIn IS NOT NULL;";
|
|
cmd.Parameters.AddWithValue("@Date", DateTime.Now.Date.ToString("yyyy-MM-dd"));
|
|
cmd.Parameters.AddWithValue("@Status1", (int)ReservationStatus.Active);
|
|
cmd.Parameters.AddWithValue("@Status2", (int)ReservationStatus.Changed);
|
|
using (SQLiteDataReader reader = cmd.ExecuteReader())
|
|
{
|
|
while (reader.Read())
|
|
{
|
|
currentOccupancies.Add((reader.GetDateTime(3), reader.GetInt32(0), reader.GetString(1), reader.GetString(2)));
|
|
}
|
|
}
|
|
}
|
|
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
|
{
|
|
cmd.CommandText = "SELECT RoomNum FROM reservations " +
|
|
"INNER JOIN guests ON reservations.GuestID = guests.ID " +
|
|
"INNER JOIN rooms ON reservations.RoomNum = rooms.ID " +
|
|
"WHERE DATE (@Date) = EndDate AND Status IN (@Status1);";
|
|
cmd.Parameters.AddWithValue("@Date", DateTime.Now.AddDays(-1).Date.ToString("yyyy-MM-dd"));
|
|
cmd.Parameters.AddWithValue("@Status1", (int)ReservationStatus.Ended);
|
|
using (SQLiteDataReader reader = cmd.ExecuteReader())
|
|
{
|
|
while (reader.Read())
|
|
{
|
|
foreach (int item in reader.GetValues())
|
|
{
|
|
previousOccupancies.Add(item);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
Transaction.Commit();
|
|
}
|
|
return (currentOccupancies, previousOccupancies);
|
|
}
|
|
internal static List<Reservation> GetDailyArrivals()
|
|
{
|
|
List<Reservation> reservations = new();
|
|
using (Database Manager = new())
|
|
{
|
|
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
|
{
|
|
cmd.CommandText = "SELECT * FROM reservations " +
|
|
"INNER JOIN transactions ON reservations.TransactionID = transactions.ID " +
|
|
"INNER JOIN guests ON reservations.GuestID = guests.ID " +
|
|
"WHERE DATE (@Date) = StartDate AND Status IN (@Status1,@Status2)" +
|
|
"ORDER BY Lname ASC;";
|
|
cmd.Parameters.AddWithValue("@Date", DateTime.Now.Date.ToString("yyyy-MM-dd"));
|
|
cmd.Parameters.AddWithValue("@Status1", (int)ReservationStatus.Active);
|
|
cmd.Parameters.AddWithValue("@Status2", (int)ReservationStatus.Changed);
|
|
using (SQLiteDataReader reader = cmd.ExecuteReader())
|
|
{
|
|
while (reader.Read())
|
|
{
|
|
Reservation? r;
|
|
Transaction? t;
|
|
Guest g;
|
|
int? RoomNumber = null;
|
|
DateTime? CheckIn = null, CheckOut = null, DateChanged = null, LastPaid = null, PaidOn = null;
|
|
|
|
if (reader.HasRows && !reader.IsDBNull(0))
|
|
{
|
|
if (reader[21].GetType() != typeof(DBNull))
|
|
{
|
|
LastPaid = reader.GetDateTime(21);
|
|
}
|
|
|
|
if (reader[22].GetType() != typeof(DBNull))
|
|
{
|
|
PaidOn = reader.GetDateTime(22);
|
|
}
|
|
|
|
t = new(reader.GetInt32(13), reader.GetDouble(14), reader.GetDouble(15), reader.GetDouble(17), reader.GetDateTime(20),
|
|
LastPaid: LastPaid, PaidOn: PaidOn, RefundAmount: reader.GetDouble(18), Penalty: reader.GetDouble(16), AmountPaid: reader.GetDouble(19));
|
|
|
|
g = new(reader.GetInt32(23), reader.GetString(24), reader.GetString(25), reader.GetString(26), reader.GetString(27), reader.GetString(28), reader.GetString(29));
|
|
|
|
if (reader[1].GetType() != typeof(DBNull))
|
|
{
|
|
RoomNumber = reader.GetInt32(1);
|
|
}
|
|
|
|
if (reader[10].GetType() != typeof(DBNull))
|
|
{
|
|
CheckIn = reader.GetDateTime(10);
|
|
}
|
|
|
|
if (reader[11].GetType() != typeof(DBNull))
|
|
{
|
|
CheckOut = reader.GetDateTime(11);
|
|
}
|
|
|
|
if (reader[12].GetType() != typeof(DBNull))
|
|
{
|
|
DateChanged = reader.GetDateTime(12);
|
|
}
|
|
|
|
r = new(reader.GetInt32(0), g, t, (ReservationType)reader.GetInt32(5), (ReservationStatus)reader.GetInt32(6),
|
|
reader.GetDateTime(7), reader.GetDateTime(8), reader.GetDateTime(9), RoomNum: RoomNumber, IsNoShow: reader.GetBoolean(4),
|
|
CheckIn: CheckIn, CheckOut: CheckOut, DateChanged: DateChanged);
|
|
reservations.Add(r);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return reservations;
|
|
}
|
|
internal static (double, double, List<(DateTime, double)>) GetIncentiveTransactions()
|
|
{
|
|
double losses;
|
|
double totalLosses = 0;
|
|
int days = 30;
|
|
DateTime dt = DateTime.Now;
|
|
List<(DateTime, double)> dailyLosses = new();
|
|
using (Database Manager = new())
|
|
{
|
|
for (int i = 0; i < days; i++)
|
|
{
|
|
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
|
{
|
|
cmd.CommandText = "SELECT sum(((julianday(EndDate) - julianday(StartDate)) * transactions.Rate) - transactions.Owed) AS Loss " +
|
|
"FROM reservations " +
|
|
"INNER JOIN transactions ON reservations.TransactionID = transactions.ID " +
|
|
"WHERE (DATE(@Date) BETWEEN StartDate AND EndDate) AND STATUS IN (@Status1,@Status2) AND Type = @Type";
|
|
cmd.Parameters.AddWithValue("@Date", dt.AddDays(i).Date.ToString("yyyy-MM-dd"));
|
|
cmd.Parameters.AddWithValue("@Status1", (int)ReservationStatus.Active);
|
|
cmd.Parameters.AddWithValue("@Status2", (int)ReservationStatus.Changed);
|
|
cmd.Parameters.AddWithValue("@Type", (int)ReservationType.Incentive);
|
|
using (SQLiteDataReader reader = cmd.ExecuteReader())
|
|
{
|
|
reader.Read();
|
|
if (reader.HasRows && !reader.IsDBNull(0))
|
|
{
|
|
totalLosses += reader.GetDouble(0);
|
|
losses = reader.GetDouble(0);
|
|
}
|
|
else
|
|
{
|
|
losses = 0;
|
|
}
|
|
}
|
|
}
|
|
dailyLosses.Add((dt.AddDays(i), losses));
|
|
}
|
|
}
|
|
return (totalLosses, totalLosses / 30, dailyLosses);
|
|
}
|
|
internal static (List<(DateTime, double)>, double, double) GetExpectedIncomeCount()
|
|
{
|
|
double totalIncome = 0;
|
|
double income;
|
|
int days = 30;
|
|
DateTime dt = DateTime.Now;
|
|
List<(DateTime, double)> dailyIncomes = new();
|
|
using (Database Manager = new())
|
|
{
|
|
for (int i = 0; i < days; i++)
|
|
{
|
|
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
|
{
|
|
cmd.CommandText = "SELECT sum(transactions.Owed) FROM reservations " +
|
|
"INNER JOIN transactions ON reservations.TransactionID = transactions.ID " +
|
|
"WHERE (DATE(@Date) BETWEEN StartDate AND EndDate) AND Status IN (@Status1,@Status2);";
|
|
cmd.Parameters.AddWithValue("@Date", dt.AddDays(i).Date.ToString("yyyy-MM-dd"));
|
|
cmd.Parameters.AddWithValue("@Status1", (int)ReservationStatus.Active);
|
|
cmd.Parameters.AddWithValue("@Status2", (int)ReservationStatus.Changed);
|
|
|
|
using (SQLiteDataReader reader = cmd.ExecuteReader())
|
|
{
|
|
reader.Read();
|
|
if (reader.HasRows && !reader.IsDBNull(0))
|
|
{
|
|
totalIncome += reader.GetDouble(0);
|
|
income = reader.GetDouble(0);
|
|
}
|
|
else
|
|
{
|
|
income = 0;
|
|
}
|
|
}
|
|
}
|
|
dailyIncomes.Add((dt.AddDays(i), income));
|
|
}
|
|
}
|
|
return (dailyIncomes, totalIncome, totalIncome / 30);
|
|
}
|
|
internal static (double, List<(DateTime, int, int, int, int, int)>) GetExpectedOccupancyCount()
|
|
{
|
|
double thirtyDayOcc = 0;
|
|
int days = 30;
|
|
DateTime dt = DateTime.Now;
|
|
List<(DateTime, int, int, int, int, int)> occData = new();
|
|
using (Database Manager = new())
|
|
{
|
|
for (int i = 0; i < days; i++)
|
|
{
|
|
int rooms, conventional, prepaid, sixty, incentive;
|
|
using (SQLiteTransaction Transaction = Manager.con.BeginTransaction())
|
|
{
|
|
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
|
{
|
|
cmd.CommandText = "SELECT COUNT(*) " +
|
|
"FROM reservations " +
|
|
"WHERE (DATE(@Date) BETWEEN StartDate AND EndDate) AND Status in (@Status1,@Status2);";
|
|
cmd.Parameters.AddWithValue("@Date", dt.AddDays(i).Date.ToString("yyyy-MM-dd"));
|
|
cmd.Parameters.AddWithValue("@Status1", (int)ReservationStatus.Active);
|
|
cmd.Parameters.AddWithValue("@Status2", (int)ReservationStatus.Changed);
|
|
|
|
using (SQLiteDataReader reader = cmd.ExecuteReader())
|
|
{
|
|
reader.Read();
|
|
if (reader.HasRows && !reader.IsDBNull(0))
|
|
{
|
|
thirtyDayOcc += reader.GetInt32(0);
|
|
rooms = reader.GetInt32(0);
|
|
}
|
|
else
|
|
{
|
|
rooms = 0;
|
|
}
|
|
}
|
|
}
|
|
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
|
{
|
|
cmd.CommandText = "SELECT COUNT(*) " +
|
|
"FROM reservations " +
|
|
"WHERE (DATE(@Date) BETWEEN StartDate AND EndDate) AND Status in (@Status1,@Status2) AND Type = 0;";
|
|
cmd.Parameters.AddWithValue("@Date", dt.AddDays(i).Date.ToString("yyyy-MM-dd"));
|
|
cmd.Parameters.AddWithValue("@Status1", (int)ReservationStatus.Active);
|
|
cmd.Parameters.AddWithValue("@Status2", (int)ReservationStatus.Changed);
|
|
|
|
using (SQLiteDataReader reader = cmd.ExecuteReader())
|
|
{
|
|
reader.Read();
|
|
if (reader.HasRows && !reader.IsDBNull(0))
|
|
{
|
|
conventional = reader.GetInt32(0);
|
|
}
|
|
else
|
|
{
|
|
conventional = 0;
|
|
}
|
|
}
|
|
}
|
|
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
|
{
|
|
cmd.CommandText = "SELECT COUNT(*) " +
|
|
"FROM reservations " +
|
|
"WHERE (DATE(@Date) BETWEEN StartDate AND EndDate) AND Status in (@Status1,@Status2) AND Type = 1;";
|
|
cmd.Parameters.AddWithValue("@Date", dt.AddDays(i).Date.ToString("yyyy-MM-dd"));
|
|
cmd.Parameters.AddWithValue("@Status1", (int)ReservationStatus.Active);
|
|
cmd.Parameters.AddWithValue("@Status2", (int)ReservationStatus.Changed);
|
|
|
|
using (SQLiteDataReader reader = cmd.ExecuteReader())
|
|
{
|
|
reader.Read();
|
|
if (reader.HasRows && !reader.IsDBNull(0))
|
|
{
|
|
prepaid = reader.GetInt32(0);
|
|
}
|
|
else
|
|
{
|
|
prepaid = 0;
|
|
}
|
|
}
|
|
}
|
|
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
|
{
|
|
cmd.CommandText = "SELECT COUNT(*) " +
|
|
"FROM reservations " +
|
|
"WHERE (DATE(@Date) BETWEEN StartDate AND EndDate) AND Status in (@Status1,@Status2) AND Type = 2;";
|
|
cmd.Parameters.AddWithValue("@Date", dt.AddDays(i).Date.ToString("yyyy-MM-dd"));
|
|
cmd.Parameters.AddWithValue("@Status1", (int)ReservationStatus.Active);
|
|
cmd.Parameters.AddWithValue("@Status2", (int)ReservationStatus.Changed);
|
|
|
|
using (SQLiteDataReader reader = cmd.ExecuteReader())
|
|
{
|
|
reader.Read();
|
|
if (reader.HasRows && !reader.IsDBNull(0))
|
|
{
|
|
sixty = reader.GetInt32(0);
|
|
}
|
|
else
|
|
{
|
|
sixty = 0;
|
|
}
|
|
}
|
|
}
|
|
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
|
{
|
|
cmd.CommandText = "SELECT COUNT(*) " +
|
|
"FROM reservations " +
|
|
"WHERE (DATE(@Date) BETWEEN StartDate AND EndDate) AND Status in (@Status1,@Status2) AND Type = 3;";
|
|
cmd.Parameters.AddWithValue("@Date", dt.AddDays(i).Date.ToString("yyyy-MM-dd"));
|
|
cmd.Parameters.AddWithValue("@Status1", (int)ReservationStatus.Active);
|
|
cmd.Parameters.AddWithValue("@Status2", (int)ReservationStatus.Changed);
|
|
|
|
using (SQLiteDataReader reader = cmd.ExecuteReader())
|
|
{
|
|
reader.Read();
|
|
if (reader.HasRows && !reader.IsDBNull(0))
|
|
{
|
|
incentive = reader.GetInt32(0);
|
|
}
|
|
else
|
|
{
|
|
incentive = 0;
|
|
}
|
|
}
|
|
}
|
|
Transaction.Commit();
|
|
}
|
|
occData.Add((dt.AddDays(i), rooms, conventional, prepaid, sixty, incentive));
|
|
}
|
|
}
|
|
return (thirtyDayOcc / days, occData);
|
|
}
|
|
internal static (int, bool) AvgOccupancySpan(DateTime Start, DateTime End)
|
|
{
|
|
int thirtyDayOcc = 0;
|
|
bool maxCapacityInRange = false;
|
|
int days = (int)(End.Date - Start.Date).TotalDays;
|
|
using (Database Manager = new())
|
|
{
|
|
for (int i = 0; i < days; i++)
|
|
{
|
|
using SQLiteCommand cmd = Manager.con.CreateCommand();
|
|
cmd.CommandText = $@"SELECT COUNT(*)
|
|
FROM reservations
|
|
WHERE (DATE(@Date) BETWEEN StartDate AND EndDate) AND Status in (@Status1,@Status2);";
|
|
cmd.Parameters.AddWithValue("@Date", Start.AddDays(i).Date.ToString("yyyy-MM-dd"));
|
|
cmd.Parameters.AddWithValue("@Status1", (int)ReservationStatus.Active);
|
|
cmd.Parameters.AddWithValue("@Status2", (int)ReservationStatus.Changed);
|
|
|
|
using SQLiteDataReader reader = cmd.ExecuteReader();
|
|
reader.Read();
|
|
if (reader.HasRows && !reader.IsDBNull(0))
|
|
{
|
|
thirtyDayOcc += reader.GetInt32(0);
|
|
if (reader.GetInt32(0) == 45)
|
|
{
|
|
maxCapacityInRange = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return (thirtyDayOcc / days, maxCapacityInRange);
|
|
}
|
|
internal static Guest? GetGuestByEmail(string Email)
|
|
{
|
|
Guest? g = null;
|
|
using (Database Manager = new())
|
|
{
|
|
using SQLiteCommand cmd = Manager.con.CreateCommand();
|
|
cmd.CommandText = $"SELECT * FROM guests WHERE Email = @Email";
|
|
cmd.Parameters.AddWithValue("@Email", Email);
|
|
using SQLiteDataReader reader = cmd.ExecuteReader();
|
|
reader.Read();
|
|
if (reader.HasRows)
|
|
{
|
|
string? CreditCard = null, Expiration = null, CCV = null;
|
|
if (reader[4].GetType() != typeof(DBNull))
|
|
{
|
|
CreditCard = reader[4].ToString();
|
|
}
|
|
|
|
if (reader[5].GetType() != typeof(DBNull))
|
|
{
|
|
Expiration = reader[5].ToString();
|
|
}
|
|
|
|
if (reader[6].GetType() != typeof(DBNull))
|
|
{
|
|
CCV = reader[6].ToString();
|
|
}
|
|
|
|
g = new(reader.GetInt32(0), reader.GetString(1), reader.GetString(2), reader.GetString(3), CreditCard, Expiration, CCV);
|
|
}
|
|
}
|
|
return g;
|
|
}
|
|
internal static Reservation? GetResByGuest(Guest g)
|
|
{
|
|
Reservation? r = null;
|
|
Transaction? t;
|
|
using (Database Manager = new())
|
|
{
|
|
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
|
{
|
|
int? RoomNumber = null;
|
|
DateTime? CheckIn = null, CheckOut = null, DateChanged = null, LastPaid = null, PaidOn = null;
|
|
|
|
cmd.CommandText = @"SELECT * FROM reservations
|
|
INNER JOIN transactions ON reservations.TransactionID = transactions.ID
|
|
WHERE GuestID = @GuestID AND Status = @Status;";
|
|
cmd.Parameters.AddWithValue("@GuestID", g.Id);
|
|
cmd.Parameters.AddWithValue("@Status", (int)ReservationStatus.Active);
|
|
|
|
using (SQLiteDataReader reader = cmd.ExecuteReader())
|
|
{
|
|
reader.Read();
|
|
if (reader.HasRows)
|
|
{
|
|
if (reader[21].GetType() != typeof(DBNull))
|
|
{
|
|
LastPaid = reader.GetDateTime(21);
|
|
}
|
|
|
|
if (reader[22].GetType() != typeof(DBNull))
|
|
{
|
|
PaidOn = reader.GetDateTime(22);
|
|
}
|
|
|
|
t = new(reader.GetInt32(13), reader.GetDouble(14), reader.GetDouble(15), reader.GetDouble(17), reader.GetDateTime(20),
|
|
LastPaid: LastPaid, PaidOn: PaidOn, RefundAmount: reader.GetDouble(18), Penalty: reader.GetDouble(16), AmountPaid: reader.GetDouble(19));
|
|
|
|
if (reader[1].GetType() != typeof(DBNull))
|
|
{
|
|
RoomNumber = reader.GetInt32(1);
|
|
}
|
|
|
|
if (reader[10].GetType() != typeof(DBNull))
|
|
{
|
|
CheckIn = reader.GetDateTime(10);
|
|
}
|
|
|
|
if (reader[11].GetType() != typeof(DBNull))
|
|
{
|
|
CheckOut = reader.GetDateTime(11);
|
|
}
|
|
|
|
if (reader[12].GetType() != typeof(DBNull))
|
|
{
|
|
DateChanged = reader.GetDateTime(12);
|
|
}
|
|
|
|
r = new(reader.GetInt32(0), g, t, (ReservationType)reader.GetInt32(5), (ReservationStatus)reader.GetInt32(6),
|
|
reader.GetDateTime(7), reader.GetDateTime(8), reader.GetDateTime(9), RoomNum: RoomNumber, IsNoShow: reader.GetBoolean(4),
|
|
CheckIn: CheckIn, CheckOut: CheckOut, DateChanged: DateChanged);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return r;
|
|
}
|
|
internal static TimeRefs? CanBeCheckedIn(string Email)
|
|
{
|
|
TimeRefs? status = null;
|
|
using (Database Manager = new())
|
|
{
|
|
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
|
{
|
|
cmd.CommandText = $"SELECT * FROM reservation WHERE Email = @Email AND Status IN (0,1)";
|
|
cmd.Parameters.AddWithValue("@Email", Email);
|
|
using (SQLiteDataReader reader = cmd.ExecuteReader())
|
|
{
|
|
reader.Read();
|
|
if (reader.HasRows)
|
|
{
|
|
DateTime dt = reader.GetDateTime(8);
|
|
if (dt.Date == DateTime.Now.Date)
|
|
{
|
|
status = TimeRefs.OnTime;
|
|
}
|
|
else if (dt.Date > DateTime.Now.Date)
|
|
{
|
|
status = TimeRefs.Late;
|
|
}
|
|
else if (dt.Date < DateTime.Now.Date)
|
|
{
|
|
status = TimeRefs.Early;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
status = null;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return status;
|
|
}
|
|
internal static double? GetBaseRate()
|
|
{
|
|
double? rate;
|
|
using (Database Manager = new())
|
|
{
|
|
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
|
{
|
|
string query = "SELECT Rate FROM rates WHERE DefaultRate = 1;";
|
|
cmd.CommandText = query;
|
|
using (SQLiteDataReader reader = cmd.ExecuteReader())
|
|
{
|
|
reader.Read();
|
|
if (reader.HasRows)
|
|
{
|
|
rate = reader.GetDouble(0);
|
|
}
|
|
else
|
|
{
|
|
rate = null;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return rate;
|
|
}
|
|
internal static bool GetBaseRateByDate(DateTime dt)
|
|
{
|
|
bool configured;
|
|
using (Database Manager = new())
|
|
{
|
|
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
|
{
|
|
string query = "SELECT Rate FROM rates WHERE DateSet = @Date;";
|
|
cmd.CommandText = query;
|
|
cmd.Parameters.AddWithValue("@Date", dt.ToString("yyyy-MM-dd"));
|
|
using (SQLiteDataReader reader = cmd.ExecuteReader())
|
|
{
|
|
reader.Read();
|
|
if (reader.HasRows)
|
|
{
|
|
configured = true;
|
|
}
|
|
else
|
|
{
|
|
configured = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return configured;
|
|
}
|
|
internal static void SetBaseRate(double Rate, DateTime DateSet, bool? DefaultRate = null)
|
|
{
|
|
using (Database Manager = new())
|
|
{
|
|
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
|
{
|
|
string query = $"INSERT INTO rates (Rate, DateSet, DefaultRate) VALUES (@Rate, @DateSet, @DefaultRate);";
|
|
cmd.CommandText = query;
|
|
cmd.Parameters.AddWithValue("@Rate", Rate);
|
|
cmd.Parameters.AddWithValue("@DateSet", DateSet.ToString("yyyy-MM-dd"));
|
|
if (DefaultRate != null)
|
|
{
|
|
if (DefaultRate.Value == true)
|
|
{
|
|
cmd.Parameters.AddWithValue("@DefaultRate", Convert.ToInt32(DefaultRate));
|
|
}
|
|
else
|
|
{
|
|
cmd.Parameters.AddWithValue("@DefaultRate", null);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
cmd.Parameters.AddWithValue("@DefaultRate", null);
|
|
}
|
|
|
|
cmd.ExecuteNonQuery();
|
|
}
|
|
}
|
|
}
|
|
internal static void UpdateBaseRate(double Rate, DateTime DateSet, bool? DefaultRate = null)
|
|
{
|
|
using (Database Manager = new())
|
|
{
|
|
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
|
{
|
|
if (DefaultRate != null)
|
|
{
|
|
if (DefaultRate.Value == true)
|
|
{
|
|
cmd.CommandText = $"UPDATE rates SET rate = @Rate, defaultrate = @DefaultRate WHERE DateSet = @Date;";
|
|
cmd.Parameters.AddWithValue("@DefaultRate", Convert.ToInt32(DefaultRate));
|
|
}
|
|
else
|
|
{
|
|
cmd.CommandText = $"UPDATE rates SET rate = @Rate WHERE DateSet = @Date;";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
cmd.CommandText = $"UPDATE rates SET rate = @Rate WHERE DateSet = @Date;";
|
|
}
|
|
cmd.Parameters.AddWithValue("@Rate", Rate);
|
|
cmd.Parameters.AddWithValue("@Date", DateSet.ToString("yyyy-MM-dd"));
|
|
cmd.ExecuteNonQuery();
|
|
}
|
|
}
|
|
}
|
|
internal static bool CheckBaseRate()
|
|
{
|
|
int? OldId = null;
|
|
bool Success = true;
|
|
using (Database Manager = new())
|
|
{
|
|
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
|
{
|
|
string query = "SELECT Id FROM rates WHERE DefaultRate = 1;";
|
|
cmd.CommandText = query;
|
|
using (SQLiteDataReader reader = cmd.ExecuteReader())
|
|
{
|
|
reader.Read();
|
|
if (reader.HasRows)
|
|
{
|
|
OldId = reader.GetInt32(0);
|
|
}
|
|
}
|
|
}
|
|
int? Id;
|
|
if (OldId != null)
|
|
{
|
|
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
|
{
|
|
string query = "SELECT Id FROM rates WHERE DateSet = @Date;";
|
|
cmd.CommandText = query;
|
|
cmd.Parameters.AddWithValue("@Date", DateTime.Now.Date.ToString("yyyy-MM-dd"));
|
|
using (SQLiteDataReader reader = cmd.ExecuteReader())
|
|
{
|
|
reader.Read();
|
|
if (reader.HasRows)
|
|
{
|
|
Id = reader.GetInt32(0);
|
|
}
|
|
else
|
|
{
|
|
Id = null;
|
|
}
|
|
}
|
|
}
|
|
if (Id != null)
|
|
{
|
|
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
|
{
|
|
cmd.CommandText = @"UPDATE rates SET DefaultRate = NULL WHERE Id = @OldID;
|
|
UPDATE rates SET DefaultRate = 1 WHERE Id = @ID";
|
|
cmd.Parameters.AddWithValue("@OldID", OldId);
|
|
cmd.Parameters.AddWithValue("@ID", Id);
|
|
cmd.ExecuteNonQuery();
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Success = false;
|
|
}
|
|
}
|
|
return Success;
|
|
}
|
|
internal static int? CheckInGuest(string Email, DateTime CheckIn)
|
|
{
|
|
int? RoomID = null;
|
|
using (Database Manager = new())
|
|
{
|
|
using (SQLiteTransaction Transaction = Manager.con.BeginTransaction())
|
|
{
|
|
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
|
{
|
|
cmd.CommandText = "UPDATE reservations SET RoomNum = (SELECT ID FROM rooms WHERE Occupied = 0 LIMIT 1), CheckIn = @Date " +
|
|
"WHERE GuestID = (SELECT ID FROM guests WHERE Email = @Email) AND RoomNum IS NULL AND Status in (@SActive,@SChanged);";
|
|
cmd.Parameters.AddWithValue("@Email", Email);
|
|
cmd.Parameters.AddWithValue("@SActive", (int)ReservationStatus.Active);
|
|
cmd.Parameters.AddWithValue("@SChanged", (int)ReservationStatus.Changed);
|
|
cmd.Parameters.AddWithValue("@Date", CheckIn.ToString("yyyy-MM-dd"));
|
|
cmd.ExecuteNonQuery();
|
|
}
|
|
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
|
{
|
|
cmd.CommandText = "UPDATE rooms SET Occupied = 1 " +
|
|
"WHERE ID = (SELECT RoomNum FROM reservations WHERE GuestID = (SELECT ID FROM guests WHERE Email = @Email AND Status in (@SActive,@SChanged))));";
|
|
cmd.Parameters.AddWithValue("@Email", Email);
|
|
cmd.Parameters.AddWithValue("@SActive", (int)ReservationStatus.Active);
|
|
cmd.Parameters.AddWithValue("@SChanged", (int)ReservationStatus.Changed);
|
|
cmd.ExecuteNonQuery();
|
|
}
|
|
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
|
{
|
|
cmd.CommandText = "SELECT RoomNum FROM reservations WHERE GuestID = (SELECT ID FROM guests WHERE Email = @Email AND Status in (@SActive,@SChanged))";
|
|
cmd.Parameters.AddWithValue("@Email", Email);
|
|
cmd.Parameters.AddWithValue("@SActive", (int)ReservationStatus.Active);
|
|
cmd.Parameters.AddWithValue("@SChanged", (int)ReservationStatus.Changed);
|
|
using (SQLiteDataReader reader = cmd.ExecuteReader())
|
|
{
|
|
reader.Read();
|
|
if (reader.HasRows)
|
|
{
|
|
RoomID = (int)reader.GetValue(0);
|
|
}
|
|
}
|
|
}
|
|
Transaction.Commit();
|
|
}
|
|
}
|
|
return RoomID;
|
|
}
|
|
internal static bool GuestCurrentlyCheckedIn(string Email)
|
|
{
|
|
bool EntryFound;
|
|
using (Database Manager = new())
|
|
{
|
|
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
|
{
|
|
cmd.CommandText = "SELECT * FROM reservations " +
|
|
"WHERE GuestID = (SELECT ID FROM guests WHERE Email = @Email AND Status in (@SActive,@SChanged)) AND CheckIn IS NOT NULL";
|
|
cmd.Parameters.AddWithValue("@Email", Email);
|
|
cmd.Parameters.AddWithValue("@SActive", (int)ReservationStatus.Active);
|
|
cmd.Parameters.AddWithValue("@SChanged", (int)ReservationStatus.Changed);
|
|
using (SQLiteDataReader reader = cmd.ExecuteReader())
|
|
{
|
|
reader.Read();
|
|
if (reader.HasRows)
|
|
{
|
|
EntryFound = true;
|
|
}
|
|
else
|
|
{
|
|
EntryFound = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return EntryFound;
|
|
}
|
|
internal static void CheckOutGuest(string Email, DateTime CheckOut)
|
|
{
|
|
using (Database Manager = new())
|
|
{
|
|
using (SQLiteTransaction Transaction = Manager.con.BeginTransaction())
|
|
{
|
|
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
|
{
|
|
cmd.CommandText = "UPDATE rooms SET Occupied = 0 " +
|
|
"WHERE ID = (SELECT RoomNum FROM reservations WHERE GuestID = (SELECT ID FROM guests WHERE Email = @Email AND Status in (@SActive,@SChanged)));";
|
|
cmd.Parameters.AddWithValue("@Email", Email);
|
|
cmd.Parameters.AddWithValue("@SActive", (int)ReservationStatus.Active);
|
|
cmd.Parameters.AddWithValue("@SChanged", (int)ReservationStatus.Changed);
|
|
cmd.ExecuteNonQuery();
|
|
}
|
|
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
|
{
|
|
cmd.CommandText = "UPDATE reservations SET CheckOut = @Date, Status = @Status " +
|
|
"WHERE GuestID = (SELECT ID FROM guests WHERE Email = @Email) AND RoomNum IS NOT NULL AND Status in (@SActive,@SChanged) AND CheckIn IS NULL;";
|
|
cmd.Parameters.AddWithValue("@Email", Email);
|
|
cmd.Parameters.AddWithValue("@Status", (int)ReservationStatus.Ended);
|
|
cmd.Parameters.AddWithValue("@SActive", (int)ReservationStatus.Active);
|
|
cmd.Parameters.AddWithValue("@SChanged", (int)ReservationStatus.Changed);
|
|
cmd.Parameters.AddWithValue("@Date", CheckOut.ToString("yyyy-MM-dd"));
|
|
cmd.ExecuteNonQuery();
|
|
}
|
|
Transaction.Commit();
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
internal static List<Reservation> GetActiveSixtyDayRes()
|
|
{
|
|
List<Reservation> list = new();
|
|
using (Database Manager = new())
|
|
{
|
|
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
|
{
|
|
cmd.CommandText = "SELECT * FROM reservations " +
|
|
"INNER JOIN transactions ON reservations.TransactionID = transactions.ID " +
|
|
"INNER JOIN guests ON reservations.GuestID = guests.ID " +
|
|
"WHERE Type = @Type AND Status IN (@Status1,@Status2);";
|
|
cmd.Parameters.AddWithValue("@Type", (int)ReservationType.SixtyDayAdvance);
|
|
cmd.Parameters.AddWithValue("@Status1", (int)ReservationStatus.Active);
|
|
cmd.Parameters.AddWithValue("@Status2", (int)ReservationStatus.Changed);
|
|
cmd.ExecuteNonQuery();
|
|
|
|
using (SQLiteDataReader reader = cmd.ExecuteReader())
|
|
{
|
|
while (reader.Read())
|
|
{
|
|
Reservation? r;
|
|
Transaction? t;
|
|
Guest g;
|
|
int? RoomNumber = null;
|
|
DateTime? CheckIn = null, CheckOut = null, DateChanged = null, LastPaid = null, PaidOn = null;
|
|
|
|
if (reader.HasRows)
|
|
{
|
|
if (reader[21].GetType() != typeof(DBNull))
|
|
{
|
|
LastPaid = reader.GetDateTime(21);
|
|
}
|
|
|
|
if (reader[22].GetType() != typeof(DBNull))
|
|
{
|
|
PaidOn = reader.GetDateTime(22);
|
|
}
|
|
|
|
t = new(reader.GetInt32(13), reader.GetDouble(14), reader.GetDouble(15), reader.GetDouble(17), reader.GetDateTime(20),
|
|
LastPaid: LastPaid, PaidOn: PaidOn, RefundAmount: reader.GetDouble(18), Penalty: reader.GetDouble(16), AmountPaid: reader.GetDouble(19));
|
|
|
|
g = new(reader.GetInt32(23), reader.GetString(24), reader.GetString(25), reader.GetString(26), reader.GetString(27), reader.GetString(28), reader.GetString(29));
|
|
|
|
if (reader[1].GetType() != typeof(DBNull))
|
|
{
|
|
RoomNumber = reader.GetInt32(1);
|
|
}
|
|
|
|
if (reader[10].GetType() != typeof(DBNull))
|
|
{
|
|
CheckIn = reader.GetDateTime(10);
|
|
}
|
|
|
|
if (reader[11].GetType() != typeof(DBNull))
|
|
{
|
|
CheckOut = reader.GetDateTime(11);
|
|
}
|
|
|
|
if (reader[12].GetType() != typeof(DBNull))
|
|
{
|
|
DateChanged = reader.GetDateTime(12);
|
|
}
|
|
|
|
r = new(reader.GetInt32(0), g, t, (ReservationType)reader.GetInt32(5), (ReservationStatus)reader.GetInt32(6),
|
|
reader.GetDateTime(7), reader.GetDateTime(8), reader.GetDateTime(9), RoomNum: RoomNumber, IsNoShow: reader.GetBoolean(4),
|
|
CheckIn: CheckIn, CheckOut: CheckOut, DateChanged: DateChanged);
|
|
list.Add(r);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return list;
|
|
}
|
|
internal static List<Reservation> GetPastDueReservations()
|
|
{
|
|
List<Reservation> list = new();
|
|
using (Database Manager = new())
|
|
{
|
|
using SQLiteTransaction Transaction = Manager.con.BeginTransaction();
|
|
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
|
{
|
|
cmd.CommandText = "SELECT * FROM reservations " +
|
|
"INNER JOIN transactions ON reservations.TransactionID = transactions.ID " +
|
|
"INNER JOIN guests ON reservations.GuestID = guests.ID " +
|
|
"WHERE DATE(@Date) > StartDate AND Status IN (@Status1,@Status2) AND CheckIn IS NULL;";
|
|
cmd.Parameters.AddWithValue("@Date", DateTime.Now.Date.ToString("yyyy-MM-dd"));
|
|
cmd.Parameters.AddWithValue("@Status1", (int)ReservationStatus.Active);
|
|
cmd.Parameters.AddWithValue("@Status2", (int)ReservationStatus.Changed);
|
|
using (SQLiteDataReader reader = cmd.ExecuteReader())
|
|
{
|
|
while (reader.Read())
|
|
{
|
|
Reservation? r;
|
|
Transaction? t;
|
|
Guest g;
|
|
int? RoomNumber = null;
|
|
DateTime? CheckIn = null, CheckOut = null, DateChanged = null, LastPaid = null, PaidOn = null;
|
|
|
|
if (reader.HasRows)
|
|
{
|
|
if (reader[21].GetType() != typeof(DBNull))
|
|
{
|
|
LastPaid = reader.GetDateTime(21);
|
|
}
|
|
|
|
if (reader[22].GetType() != typeof(DBNull))
|
|
{
|
|
PaidOn = reader.GetDateTime(22);
|
|
}
|
|
|
|
t = new(reader.GetInt32(13), reader.GetDouble(14), reader.GetDouble(15), reader.GetDouble(17), reader.GetDateTime(20),
|
|
LastPaid: LastPaid, PaidOn: PaidOn, RefundAmount: reader.GetDouble(18), Penalty: reader.GetDouble(16), AmountPaid: reader.GetDouble(19));
|
|
|
|
g = new(reader.GetInt32(23), reader.GetString(24), reader.GetString(25), reader.GetString(26), reader.GetString(27), reader.GetString(28), reader.GetString(29));
|
|
|
|
if (reader[1].GetType() != typeof(DBNull))
|
|
{
|
|
RoomNumber = reader.GetInt32(1);
|
|
}
|
|
|
|
if (reader[10].GetType() != typeof(DBNull))
|
|
{
|
|
CheckIn = reader.GetDateTime(10);
|
|
}
|
|
|
|
if (reader[11].GetType() != typeof(DBNull))
|
|
{
|
|
CheckOut = reader.GetDateTime(11);
|
|
}
|
|
|
|
if (reader[12].GetType() != typeof(DBNull))
|
|
{
|
|
DateChanged = reader.GetDateTime(12);
|
|
}
|
|
|
|
r = new(reader.GetInt32(0), g, t, (ReservationType)reader.GetInt32(5), (ReservationStatus)reader.GetInt32(6),
|
|
reader.GetDateTime(7), reader.GetDateTime(8), reader.GetDateTime(9), RoomNum: RoomNumber, IsNoShow: reader.GetBoolean(4),
|
|
CheckIn: CheckIn, CheckOut: CheckOut, DateChanged: DateChanged);
|
|
list.Add(r);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
|
{
|
|
cmd.CommandText = "UPDATE reservations SET IsNoShow = 1, DateChanged = @DateChanged " +
|
|
"WHERE DATE (@Date) > StartDate AND Status IN (@Status1,@Status2) AND CheckIn IS NULL";
|
|
cmd.Parameters.AddWithValue("@Date", DateTime.Now.Date.ToString("yyyy-MM-dd"));
|
|
cmd.Parameters.AddWithValue("@DateChanged", DateTime.Now.Date.ToString("yyyy-MM-dd"));
|
|
cmd.Parameters.AddWithValue("@Status1", (int)ReservationStatus.Active);
|
|
cmd.Parameters.AddWithValue("@Status2", (int)ReservationStatus.Changed);
|
|
cmd.ExecuteNonQuery();
|
|
}
|
|
Transaction.Commit();
|
|
}
|
|
return list;
|
|
}
|
|
}
|
|
internal enum TimeRefs
|
|
{
|
|
OnTime,
|
|
Early,
|
|
Late
|
|
}
|
|
}
|