259 lines
8.6 KiB
C#
259 lines
8.6 KiB
C#
using EnVisage.Code;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.Script.Serialization;
|
|
|
|
namespace EnVisage.Models
|
|
{
|
|
public class RatesModel
|
|
{
|
|
public enum FormMode
|
|
{
|
|
ListRates = 0,
|
|
DeleteRate = 1,
|
|
ConfirmDeleteRate = 2,
|
|
EditRate = 3,
|
|
DeriveRate = 4,
|
|
ConfirmEditRate = 5
|
|
}
|
|
|
|
public FormMode Mode { get; set; }
|
|
public RateModel EditRate { get; set; }
|
|
public Guid? EditRateId { get; set; }
|
|
public Guid? DeleteRateId { get; set; }
|
|
public Guid ExpenditureCategoryId { get; set; }
|
|
public Guid ScenarioId { get; set; }
|
|
public List<RateModel> GlobalRates { get; set; }
|
|
public List<RateModel> LocalRates { get; set; }
|
|
|
|
public RatesModel()
|
|
{
|
|
Mode = FormMode.ListRates;
|
|
LocalRates = new List<RateModel>();
|
|
GlobalRates = new List<RateModel>();
|
|
}
|
|
|
|
public void AddLocalRange(ICollection<Rate> list)
|
|
{
|
|
this.LocalRates.AddRange(list.Select(x => new RateModel() {
|
|
Id = x.Id,
|
|
Rate1 = x.Rate1,
|
|
StartDate = x.StartDate,
|
|
EndDate = x.EndDate,
|
|
ExpenditureCategoryId = x.ExpenditureCategoryId
|
|
}));
|
|
}
|
|
public void AddGlobalRange(ICollection<Rate> list)
|
|
{
|
|
this.GlobalRates.AddRange(list.Select(x => new RateModel()
|
|
{
|
|
Id = x.Id,
|
|
Rate1 = x.Rate1,
|
|
StartDate = x.StartDate,
|
|
EndDate = x.EndDate,
|
|
ExpenditureCategoryId = x.ExpenditureCategoryId
|
|
}));
|
|
}
|
|
}
|
|
|
|
public class Expenditure2ExpendituresModel : List<Expenditure2Expenditure>
|
|
{
|
|
public Expenditure2Expenditure EditExpenditure2Expenditure { get; set; }
|
|
public Nullable<Guid> EditExpenditure2ExpenditureId { get; set; }
|
|
public Nullable<Guid> DeleteExpenditure2ExpenditureId { get; set; }
|
|
|
|
public Expenditure2ExpendituresModel(ICollection<Expenditure2Expenditure> list)
|
|
{
|
|
this.AddRange(list);
|
|
}
|
|
|
|
public Expenditure2ExpendituresModel()
|
|
{
|
|
EditExpenditure2Expenditure = new Expenditure2Expenditure();
|
|
EditExpenditure2ExpenditureId = Guid.Empty;
|
|
}
|
|
}
|
|
|
|
public class FeesModel : List<FeeCalculation>
|
|
{
|
|
public FeeCalculation EditFee { get; set; }
|
|
public Nullable<Guid> EditFeeId { get; set; }
|
|
public Nullable<Guid> DeleteFeeId { get; set; }
|
|
|
|
public FeesModel(ICollection<FeeCalculation> list)
|
|
{
|
|
this.AddRange(list);
|
|
}
|
|
|
|
public FeesModel()
|
|
{
|
|
}
|
|
}
|
|
|
|
public class ExpenditureCategoryModel
|
|
{
|
|
#region Classes and enums
|
|
public enum UseTypes
|
|
{
|
|
[DisplayValue("Quantity")]
|
|
Quantity = 1,
|
|
[DisplayValue("Cost")]
|
|
Cost = 2,
|
|
[DisplayValue("Calculated")]
|
|
Calculated = 3,
|
|
[DisplayValue("Fee")]
|
|
Fee = 4
|
|
}
|
|
|
|
public enum CgEfx
|
|
{
|
|
[DisplayValue("CG")]
|
|
CG = 1,
|
|
[DisplayValue("EFX")]
|
|
EFX = 2
|
|
}
|
|
|
|
public enum CategoryTypes
|
|
{
|
|
[DisplayValue("N/A")]
|
|
Undefined = 0,
|
|
[DisplayValue("Labor")]
|
|
Labor = 1,
|
|
[DisplayValue("Materials")]
|
|
Materials = 2,
|
|
[DisplayValue("Usage")]
|
|
Usage = 3
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
public System.Guid Id { get; set; }
|
|
|
|
[Required]
|
|
[Display(Name = "Expenditure Category Name")]
|
|
public string Name { get; set; }
|
|
[Required]
|
|
[Display(Name = "Expenditure")]
|
|
public System.Guid ExpenditureId { get; set; }
|
|
[Display(Name = "GL Account")]
|
|
public System.Guid GLId { get; set; }
|
|
[Display(Name = "Unit Of Measure")]
|
|
public System.Guid UOMId { get; set; }
|
|
[Display(Name = "Cost Center")]
|
|
public System.Guid CreditId { get; set; }
|
|
[Display(Name = "Category Type")]
|
|
public CategoryTypes? Type { get; set; }
|
|
[Display(Name = "Usage")]
|
|
public UseTypes? UseType { get; set; }
|
|
[Display(Name = "CGEFX")]
|
|
public string CGEFX { get; set; }
|
|
[Display(Name = "System Attribute One")]
|
|
public Nullable<System.Guid> SystemAttributeOne { get; set; }
|
|
[Display(Name = "System Attribute Two")]
|
|
public Nullable<System.Guid> SystemAttributeTwo { get; set; }
|
|
[Display(Name = "Wks Subject To Fee")]
|
|
public Nullable<int> WksSubjectToFee { get; set; }
|
|
public ICollection<Expenditure2Expenditure> Expenditure2Expenditure { get; set; }
|
|
public ICollection<FeeCalculation> FeeCalculation { get; set; }
|
|
public RatesModel Rates { get; set; }
|
|
public FeesModel Fees { get; set; }
|
|
public Expenditure2ExpendituresModel CalculatesCategories { get; set; }
|
|
public FeeCalculation Fee { get; set; }
|
|
public Rate Rate { get; set; }
|
|
public int ScenariosCount { get; set; }
|
|
|
|
|
|
/// <summary>
|
|
/// Casts a <see cref=" ExpenditureCategory"/> obect to the object of type <see cref=" ExpenditureCategoryModel"/>.
|
|
/// </summary>
|
|
/// <param name="obj">A <see cref="Client"/> object.</param>
|
|
/// <returns>A <see cref=" ExpenditureCategoryModel"/> object filled with data from db.</returns>
|
|
public static explicit operator ExpenditureCategoryModel(ExpenditureCategory obj)
|
|
{
|
|
if (obj == null)
|
|
return null;
|
|
|
|
VW_ExpenditureCategory view = obj.GetView(); // SA. ENV-839
|
|
|
|
var model = new ExpenditureCategoryModel
|
|
{
|
|
Id = obj.Id,
|
|
ExpenditureId = obj.ExpenditureId,
|
|
GLId = obj.GLId,
|
|
UOMId = obj.UOMId,
|
|
CreditId = obj.CreditId,
|
|
Type = (CategoryTypes?)obj.Type,
|
|
UseType = (UseTypes?)obj.UseType,
|
|
CGEFX = obj.CGEFX,
|
|
SystemAttributeOne = obj.SystemAttributeOne,
|
|
SystemAttributeTwo = obj.SystemAttributeTwo,
|
|
WksSubjectToFee = obj.WksSubjectToFee,
|
|
Expenditure2Expenditure = obj.Expenditure2Expenditure,
|
|
FeeCalculation = obj.FeeCalculation,
|
|
Rates = new RatesModel(),
|
|
CalculatesCategories = new Expenditure2ExpendituresModel(),
|
|
Fee = new FeeCalculation(),
|
|
Rate = new Rate(),
|
|
ScenariosCount = obj.ScenarioDetail.Count()
|
|
};
|
|
|
|
if (view != null)
|
|
model.Name = view.ExpCategoryWithCcName; // SA. ENV-756. ENV-839
|
|
|
|
model.Rates.AddGlobalRange(obj.Rates.Where(x => x.Type == (short)RateModel.RateType.Global).ToList());
|
|
model.Rates.AddLocalRange(obj.Rates.Where(x => x.Type == (short)RateModel.RateType.Derived).ToList());
|
|
model.TrimStringProperties();
|
|
return model;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Copies data from model to DAL object.
|
|
/// </summary>
|
|
/// <param name="dbObj">A target DAL object.</param>
|
|
public void CopyTo(ExpenditureCategory dbObj)
|
|
{
|
|
if (dbObj == null)
|
|
throw new ArgumentNullException();
|
|
|
|
dbObj.ExpenditureId = ExpenditureId;
|
|
dbObj.Name = Name; // SA. ENV-756. ENV-839. Direct copiing of name from model
|
|
dbObj.GLId = GLId;
|
|
dbObj.UOMId = UOMId;
|
|
dbObj.CreditId = CreditId;
|
|
dbObj.Type = (int?)Type;
|
|
dbObj.UseType = (int?)UseType;
|
|
dbObj.CGEFX = CGEFX;
|
|
dbObj.SystemAttributeOne = SystemAttributeOne;
|
|
dbObj.SystemAttributeTwo = SystemAttributeTwo;
|
|
dbObj.WksSubjectToFee = WksSubjectToFee;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Model for ExpenditureCategory page
|
|
/// </summary>
|
|
/// <remarks>SA. ENV-723</remarks>
|
|
public class ExpenditureCategoriesListModel
|
|
{
|
|
public List<object> UnitsOfMeasure { get; set; }
|
|
|
|
public ExpenditureCategoriesListModel()
|
|
{
|
|
UnitsOfMeasure = new List<object>();
|
|
}
|
|
|
|
public string UnitsOfMeasureJson
|
|
{
|
|
get
|
|
{
|
|
JavaScriptSerializer serializer = new JavaScriptSerializer();
|
|
string json = serializer.Serialize(this.UnitsOfMeasure);
|
|
return json;
|
|
}
|
|
}
|
|
}
|
|
} |