using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Linq;
using System.Web;
using EnVisage.Code;
namespace EnVisage.Models
{
public class FiscalCalendarModel : IValidatableObject
{
#region Classes and enums
///
/// Represents a fiscal calendar type.
///
public enum FiscalCalendarType
{
///
/// Undefined = -1.
///
//[DisplayValue("")]
//Undefined = -1,
///
/// Calendar Year = 0.
///
[DisplayValue("Calendar Year")]
CalendarYear = 0,
///
/// 4-4-5 weeks calendar where each quarter contains of 3 months with 4, 4 and 5 weeks.
///
[DisplayValue("4,4,5 weeks Calendar")]
Calendar445 = 1,
///
/// 4-5-4 weeks calendar where each quarter contains of 3 months with 4, 5 and 4 weeks.
///
[DisplayValue("4,5,4 weeks Calendar")]
Calendar454 = 2,
///
/// 5-4-4 weeks calendar where each quarter contains of 3 months with 5, 4 and 4 weeks.
///
[DisplayValue("5,4,4 weeks Calendar")]
Calendar544 = 3,
}
///
/// Represents a way of ending the calendar year and distribution of weeks between quarters.
///
public enum CalendarYearType
{
[DisplayValue("52 weeks only")]
Only52Weeks = 0,
[DisplayValue("Last of the month")]
LastWeekDay = 1,
[DisplayValue("Standard Year")]
StandardYear = 2
}
///
/// Represents a fiscal year record type.
///
public enum FiscalYearType
{
Week = 0,
Month = 1,
Quarter = 2,
Year = 3
}
#endregion
#region Constructors
public FiscalCalendarModel()
{
TypeSettingId = StartDateSettingId = WeekEndingSettingId = WeekEndingTypeSettingId = Guid.Empty;
}
#endregion
#region Properties
public Guid TypeSettingId { get; set; }
public Guid StartDateSettingId { get; set; }
public Guid WeekEndingSettingId { get; set; }
public Guid WeekEndingTypeSettingId { get; set; }
[Required]
[Display(Name = "Calendar Type")]
public FiscalCalendarType? Type { get; set; }
[DataType(DataType.Date), DisplayFormat(DataFormatString = "{0:MM/dd/yy}", ApplyFormatInEditMode = true)]
[Display(Name = "Current Year Start Date")]
public DateTime? CurrentYearStartDate { get; set; }
[Display(Name = "Week Ending")]
public DayOfWeek? WeekEnding { get; set; }
[Display(Name = "Year Type")]
public CalendarYearType? WeekEndingType { get; set; }
[Display(Name = "Adjust Period")]
public bool Adjustingperiod { get; set; }
#endregion
#region Methods
///
/// Validates an object and returns a collection that holds failed-validation information.
///
///
/// A collection that holds failed-validation information.
///
/// The validation context.
public IEnumerable Validate(ValidationContext validationContext)
{
switch (Type)
{
case FiscalCalendarType.CalendarYear:
yield break;
default:
if (this.WeekEndingType == null)
yield return new ValidationResult(string.Format(Constants.ERROR_TEMPLATE_REQUIRED, "Week Ending Type"), new [] { "WeekEndingType" });
if (this.CurrentYearStartDate == null)
yield return new ValidationResult(string.Format(Constants.ERROR_TEMPLATE_REQUIRED, "Current Year Start Date"), new[] { "CurrentYearStartDate" });
break;
}
}
#endregion
}
}