This commit introduces a large number of changes. Namely there are a number of additions to a new set of classes that manage the database and/ or the models shared between the code and databse. There is fragmented non-functional code in this commit and there may be debug/ old code that still needs to be removed. This commit is just to version these changes as they were not commited previously. There is also some console interface code written, but has next to no functionality attached to any existing prompts. More details will be published per .cs file, ie specific manager or model, once they are finished as they are undergoing rapid and significant changes regularly.
190 lines
5.9 KiB
C#
190 lines
5.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Ophelias.Models;
|
|
using Ophelias.Managers;
|
|
|
|
namespace Ophelias.Models
|
|
{
|
|
internal class Transaction
|
|
{
|
|
private double PenaltyMultipler = 1.1;
|
|
|
|
internal int Id { get; set; }
|
|
internal double Rate { get; set; }
|
|
internal double Paid { get; set; }
|
|
internal double Owed { get; set; }
|
|
internal double? Penalty { get; set; }
|
|
internal double Multiplier { get; set; }
|
|
internal double RefundAmount { get; set; }
|
|
internal bool? Late { get; set; }
|
|
internal bool PaidOff { get; set; }
|
|
internal DateTime PayBy { get; set; }
|
|
internal DateTime PaidOn { get; set; }
|
|
|
|
internal Transaction(int id, Reservation r, DateTime payby)
|
|
{
|
|
Id = id;
|
|
Paid = 0;
|
|
Owed = 0;
|
|
RefundAmount = 0;
|
|
PaidOff = false;
|
|
PayBy = SetPayByDate(r);
|
|
Multiplier = Fee(r.Type);
|
|
}
|
|
private bool IsOverdue()
|
|
{
|
|
if (DateTime.Now > PayBy)
|
|
{
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
private DateTime SetPayByDate(Reservation r)
|
|
{
|
|
switch(r.Type)
|
|
{
|
|
case ReservationType.Conventional: return r.EndDate;
|
|
case ReservationType.Prepaid: return r.StartDate;
|
|
case ReservationType.Incentive: return r.EndDate;
|
|
case ReservationType.SixtyDayAdvance: return r.StartDate.AddDays(-30);
|
|
default: throw new NotImplementedException();
|
|
}
|
|
}
|
|
private void SetChangeFees(ReservationType type, double rate)
|
|
{
|
|
switch (type)
|
|
{
|
|
case ReservationType.Conventional: return;
|
|
case ReservationType.Prepaid: SetFee(PenaltyMultipler); SetRate(rate); return;
|
|
case ReservationType.Incentive: return;
|
|
case ReservationType.SixtyDayAdvance: SetFee(PenaltyMultipler); SetRate(rate); return;
|
|
default: throw new NotImplementedException();
|
|
}
|
|
}
|
|
private void CancellationHandler(ReservationType type)
|
|
{
|
|
void SetRefund()
|
|
{
|
|
if (DateTime.Now.AddDays(+3).Day <= PayBy.Day)
|
|
{
|
|
RefundAmount = Paid;
|
|
Paid = 0;
|
|
Owed = 0;
|
|
PaidOff = false;
|
|
}
|
|
}
|
|
|
|
switch (type)
|
|
{
|
|
case ReservationType.Conventional: SetRefund(); return;
|
|
case ReservationType.Prepaid: return;
|
|
case ReservationType.Incentive: SetRefund(); return;
|
|
case ReservationType.SixtyDayAdvance: return;
|
|
default: throw new NotImplementedException();
|
|
}
|
|
}
|
|
internal void Penalize(Reservation r)
|
|
{
|
|
switch (r.Status)
|
|
{
|
|
case ReservationStatus.Active: IsOverdue(); return;
|
|
case ReservationStatus.Ended: IsOverdue(); return;
|
|
case ReservationStatus.Cancelled: CancellationHandler(r.Type); return;
|
|
default: throw new NotImplementedException();
|
|
}
|
|
}
|
|
internal void Penalize(Reservation r, double rate)
|
|
{
|
|
switch(r.Status)
|
|
{
|
|
case ReservationStatus.Changed: SetChangeFees(r.Type, rate); return;
|
|
default: throw new NotImplementedException();
|
|
}
|
|
}
|
|
private double Fee(ReservationType type)
|
|
{
|
|
switch (type)
|
|
{
|
|
case ReservationType.Conventional: return 1.0;
|
|
case ReservationType.Prepaid: return 0.75;
|
|
case ReservationType.Incentive: return GetIncentiveRate();
|
|
case ReservationType.SixtyDayAdvance: return 0.85;
|
|
default: throw new NotImplementedException();
|
|
}
|
|
}
|
|
private double GetIncentiveRate()
|
|
{
|
|
return 0.80;
|
|
}
|
|
private void SetFee(double mult)
|
|
{
|
|
Multiplier = mult;
|
|
}
|
|
private void SetRate(double rate)
|
|
{
|
|
Rate = rate;
|
|
}
|
|
|
|
internal void Pay(double amount)
|
|
{
|
|
if (RefundAmount > -1)
|
|
{
|
|
return;
|
|
}
|
|
Paid += amount;
|
|
if (Paid == Owed)
|
|
{
|
|
Owed -= Paid;
|
|
PaidOn = DateTime.Now;
|
|
PaidOff = true;
|
|
} else if (Paid > Owed)
|
|
{
|
|
RefundAmount = Paid - Owed;
|
|
Owed = Owed - Paid + RefundAmount;
|
|
PaidOn = DateTime.Now;
|
|
PaidOff = true;
|
|
} else
|
|
{
|
|
Owed -= Paid;
|
|
PaidOn = DateTime.Now;
|
|
}
|
|
}
|
|
}
|
|
|
|
internal static class TransactionFees
|
|
{
|
|
static double ConventionalFee = 1.0;
|
|
static double PrepaidFee = 0.75;
|
|
static double IncentiveFee = OccupancyIncentive();
|
|
static double SixtyDayFee = 0.85;
|
|
|
|
private static double OccupancyIncentive()
|
|
{
|
|
int thirtyDayOcc;
|
|
using (DatabaseManager dbm = new DatabaseManager())
|
|
{
|
|
if (dbm.cur == null)
|
|
throw new NotImplementedException();
|
|
|
|
thirtyDayOcc = DatabaseFunctions.GetThirtyDayOccupancy(dbm.cur, DateTime.Now);
|
|
}
|
|
if ((double)(thirtyDayOcc / 45.0) <= 0.6)
|
|
return 0.80;
|
|
return 1.0;
|
|
}
|
|
|
|
}
|
|
internal class TransactionList
|
|
{
|
|
internal List<Transaction> Transactions;
|
|
|
|
internal TransactionList()
|
|
{
|
|
Transactions = new List<Transaction>();
|
|
}
|
|
}
|
|
}
|