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.
143 lines
4.7 KiB
C#
143 lines
4.7 KiB
C#
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 Transaction
|
|
{
|
|
internal int Id { get; set; }
|
|
internal double Rate { get; set; }
|
|
internal double Owed { get; set; }
|
|
internal double Penalty { get; set; }
|
|
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 Multiplier, DateTime PayBy, DateTime? LastPaid = null,
|
|
DateTime? PaidOn = null, double RefundAmount = 0, double Penalty = 0)
|
|
{
|
|
this.Id = Id;
|
|
this.Rate = Rate;
|
|
this.Owed = Owed;
|
|
this.Penalty = Penalty;
|
|
this.Multiplier = Multiplier;
|
|
this.RefundAmount = RefundAmount;
|
|
this.PayBy = PayBy;
|
|
this.LastPaid = LastPaid;
|
|
this.PaidOn = PaidOn;
|
|
}
|
|
|
|
internal void UpdateTransactionFees(double Rate, double Multiplier, DateTime PayBy)
|
|
{
|
|
this.Rate = Rate;
|
|
this.Multiplier = Multiplier;
|
|
this.PayBy = PayBy;
|
|
using (DatabaseManager Manager = new DatabaseManager())
|
|
{
|
|
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
|
{
|
|
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();
|
|
}
|
|
}
|
|
}
|
|
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())
|
|
{
|
|
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 Refund()
|
|
{
|
|
RefundAmount = 0;
|
|
using (DatabaseManager Manager = new DatabaseManager())
|
|
{
|
|
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 static class TxFunctions
|
|
{
|
|
internal static double ConventionalFee = 1.0;
|
|
internal static double PrepaidFee = 0.75;
|
|
internal static double SixtyDayFee = 0.85;
|
|
internal static double Changed = 1.1;
|
|
internal static double IncentiveFee(DateTime Start, DateTime End)
|
|
{
|
|
int thirtyDayOcc;
|
|
thirtyDayOcc = HotelManager.AvgOccupancySpan(Start, End);
|
|
if ((double)(thirtyDayOcc / 45.0) <= 0.6)
|
|
return 0.80;
|
|
return 1.0;
|
|
}
|
|
internal static DateTime GetPayByDate(ReservationType Type, DateTime StartDate, DateTime EndDate)
|
|
{
|
|
switch (Type)
|
|
{
|
|
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
|
|
{
|
|
internal List<Transaction> Transactions;
|
|
|
|
internal TransactionList()
|
|
{
|
|
Transactions = new List<Transaction>();
|
|
}
|
|
}
|
|
}
|