private void AddNewCharge(object param) { if (SelectedCategoryName != null && SelectedUnitName != null) { decimal uc; if (!decimal.TryParse(UnitCost, out uc)) { return; } decimal cs; if (!decimal.TryParse(ChargeSum, out cs)) { return; } var cc = new ChargeComponent() { ChargeComponentId = Guid.NewGuid(), CostCategoryId = SelectedCategoryName.BuildingChargeBasisCategoryId, CostDistribution = SelectedUnitName.EnumValue, CostPerUnit = uc, Sum = cs, GroupName = SelectedGroupName }; ChargeComponents.Add(cc); OnPropertyChanged("ComponentsSum"); } }
// Use this for initialization void Start() { // Get and store a reference to the Rigidbody2D component so that we can // access it. memComponent = currentPlayer.GetComponent <MemoryComponent> (); chargeComponent = GetComponent <ChargeComponent> (); }
public static void GenerateCharges(DateTime chargeDate, Guid autoChargeId) { using (var db = new DB.DomenaDBContext()) { var q = db.Buildings.Include(b => b.CostCollection); foreach (var a in db.Apartments.Where(x => !x.IsDeleted && x.SoldDate == null && q.Where(y => y.BuildingId.Equals(x.BuildingId)).FirstOrDefault().CostCollection.Count > 0)) { var c = new Charge() { ApartmentId = a.ApartmentId, ChargeId = Guid.NewGuid(), IsClosed = false, ChargeDate = chargeDate, CreatedDate = DateTime.Today, SettlementId = Guid.Empty, AutoChargeId = autoChargeId, OwnerId = a.OwnerId }; c.Components = new List <ChargeComponent>(); foreach (var costCollection in db.Buildings.Include(b => b.CostCollection).Where(x => x.BuildingId.Equals(a.BuildingId)).FirstOrDefault().CostCollection) { if (costCollection.BegginingDate > chargeDate || (costCollection.EndingDate.Year > 1901 && costCollection.EndingDate < chargeDate)) { continue; } var group = db.GroupName.FirstOrDefault(x => x.BuildingChargeGroupNameId == costCollection.BuildingChargeGroupNameId); var cc = new ChargeComponent() { ChargeComponentId = Guid.NewGuid(), CostCategoryId = costCollection.BuildingChargeBasisCategoryId, CostDistribution = costCollection.BuildingChargeBasisDistribution, CostPerUnit = costCollection.CostPerUnit, GroupName = group }; double units; switch ((CostDistribution)cc.CostDistribution) { case CostDistribution.PerApartment: units = 1; break; case CostDistribution.PerApartmentTotalArea: units = a.AdditionalArea + a.ApartmentArea; break; case CostDistribution.PerApartmentArea: units = a.ApartmentArea; break; case CostDistribution.PerAdditionalArea: units = a.AdditionalArea; break; case CostDistribution.PerLocators: units = a.Locators; break; default: units = 0; break; } cc.Sum = Math.Round((Convert.ToDecimal(units) * cc.CostPerUnit), 2); c.Components.Add(cc); db.Entry(cc.GroupName).State = EntityState.Unchanged; } db.Charges.Add(c); } db.SaveChanges(); } }
public static Charge CreateMonthlyCharge(Apartment apartment) { Charge c; using (var db = new DB.DomenaDBContext()) { var building = db.Buildings.Include(b => b.CostCollection).Where(x => x.BuildingId == apartment.BuildingId).FirstOrDefault(); c = new Charge() { ApartmentId = apartment.ApartmentId, ChargeId = Guid.NewGuid(), IsClosed = false, ChargeDate = DateTime.Today, CreatedDate = DateTime.Today, SettlementId = Guid.Empty, AutoChargeId = Guid.Empty, OwnerId = apartment.OwnerId }; c.Components = new List <ChargeComponent>(); foreach (var costCollection in building.CostCollection) { if (costCollection.BegginingDate > DateTime.Today || (costCollection.EndingDate.Year > 1901 && costCollection.EndingDate < DateTime.Today)) { continue; } var group = db.GroupName.FirstOrDefault(x => x.BuildingChargeGroupNameId == costCollection.BuildingChargeGroupNameId); var cc = new ChargeComponent() { ChargeComponentId = Guid.NewGuid(), CostCategoryId = costCollection.BuildingChargeBasisCategoryId, CostDistribution = costCollection.BuildingChargeBasisDistribution, CostPerUnit = costCollection.CostPerUnit, GroupName = group }; double units; switch ((CostDistribution)cc.CostDistribution) { case CostDistribution.PerApartment: units = 1; break; case CostDistribution.PerApartmentTotalArea: units = apartment.AdditionalArea + apartment.ApartmentArea; break; case CostDistribution.PerApartmentArea: units = apartment.ApartmentArea; break; case CostDistribution.PerAdditionalArea: units = apartment.AdditionalArea; break; case CostDistribution.PerLocators: units = apartment.Locators; break; default: units = 0; break; } cc.Sum = Math.Round((Convert.ToDecimal(units) * cc.CostPerUnit), 2); c.Components.Add(cc); } } return(c); }
public static void RecalculateCharge(Charge _charge) { using (var db = new DB.DomenaDBContext()) { var charge = db.Charges.Include(x => x.Components).FirstOrDefault(y => y.ChargeId.Equals(_charge.ChargeId)); var a = db.Apartments.FirstOrDefault(x => x.ApartmentId.Equals(charge.ApartmentId)); var b = db.Buildings.Include(x => x.CostCollection).FirstOrDefault(y => y.BuildingId.Equals(db.Apartments.FirstOrDefault(z => z.ApartmentId.Equals(charge.ApartmentId)).BuildingId)); charge.Components.RemoveAll(x => true); var nullDate = new DateTime(1900, 01, 01); foreach (var costCollection in b.CostCollection) { if (costCollection.EndingDate != nullDate && (costCollection.EndingDate < charge.ChargeDate || costCollection.BegginingDate > charge.ChargeDate)) { continue; } var group = db.GroupName.FirstOrDefault(x => x.BuildingChargeGroupNameId == costCollection.BuildingChargeGroupNameId); var cc = new ChargeComponent() { ChargeComponentId = Guid.NewGuid(), CostCategoryId = costCollection.BuildingChargeBasisCategoryId, CostDistribution = costCollection.BuildingChargeBasisDistribution, CostPerUnit = costCollection.CostPerUnit, GroupName = group }; double units; switch ((CostDistribution)cc.CostDistribution) { case CostDistribution.PerApartment: units = 1; break; case CostDistribution.PerApartmentTotalArea: units = a.AdditionalArea + a.ApartmentArea; break; case CostDistribution.PerApartmentArea: units = a.ApartmentArea; break; case CostDistribution.PerAdditionalArea: units = a.AdditionalArea; break; case CostDistribution.PerLocators: units = a.Locators; break; default: units = 0; break; } cc.Sum = Math.Round((Convert.ToDecimal(units) * cc.CostPerUnit), 2); charge.Components.Add(cc); db.Entry(cc.GroupName).State = EntityState.Unchanged; } db.SaveChanges(); } }
public AddChargeResponse Add(AddChargeRequest request) { try { var response = new AddChargeResponse(); var bc = new ChargeComponent(); response.Result = bc.Add(request.IdUser, request.Charge); return(response); } catch (Exception ex) { var httpError = new HttpResponseMessage() { StatusCode = (HttpStatusCode)422, // UNPROCESSABLE ENTITY ReasonPhrase = ex.Message }; throw new HttpResponseException(httpError); } }
public GetTop1000ChargesResponse GetTop1000Charges() { try { var response = new GetTop1000ChargesResponse(); var bc = new ChargeComponent(); response.Charges = bc.GetTop1000(); return(response); } catch (Exception ex) { var httpError = new HttpResponseMessage() { StatusCode = (HttpStatusCode)422, ReasonPhrase = ex.Message }; throw new HttpResponseException(httpError); } }
private void SaveDialog(object param) { if (_apartmentLocalCopy == null) { if (!IsValid(this as DependencyObject) || (string.IsNullOrEmpty(SelectedBuildingAddress) || string.IsNullOrEmpty(SelectedOwnerMailAddress) || ApartmentNumber <= 0 || double.Parse(AdditionalArea) < 0 || double.Parse(ApartmentArea) <= 0)) { return; } //Add new apartment using (var db = new DB.DomenaDBContext()) { var newApartment = new LibDataModel.Apartment { BoughtDate = BoughtDate.Date, ApartmentId = Guid.NewGuid(), BuildingId = SelectedBuildingName.BuildingId, AdditionalArea = double.Parse(AdditionalArea), ApartmentArea = double.Parse(ApartmentArea), IsDeleted = false, SoldDate = null, OwnerId = SelectedOwnerName.OwnerId, CreatedDate = DateTime.Now, ApartmentNumber = ApartmentNumber, MeterCollection = new List <ApartmentMeter>(), Locators = LocatorsAmount }; if (!SelectedOwnerMailAddress.Equals(db.Owners.Where(x => x.OwnerId == _apartmentLocalCopy.OwnerId).Select(x => x.MailAddress))) { newApartment.CorrespondenceAddress = SelectedOwnerMailAddress; } else { newApartment.CorrespondenceAddress = null; } var q = MeterCollection.Where(x => !x.IsDeleted); foreach (var m in q) { newApartment.MeterCollection.Add(new ApartmentMeter() { IsDeleted = false, LastMeasure = m.LastMeasure, MeterTypeParent = m.MeterTypeParent, LegalizationDate = m.LegalizationDate, MeterId = m.MeterId }); db.Entry(m.MeterTypeParent).State = EntityState.Unchanged; } db.Apartments.Add(newApartment); // Add initial charge var building = db.Buildings.Include(x => x.CostCollection).FirstOrDefault(x => x.BuildingId == newApartment.BuildingId); double percentage = 1 - (BoughtDate.Day / (double)DateTime.DaysInMonth(BoughtDate.Year, BoughtDate.Month)); var chargeDate = BoughtDate; while (chargeDate <= DateTime.Today) { var c = new Charge() { ApartmentId = newApartment.ApartmentId, ChargeId = Guid.NewGuid(), IsClosed = false, ChargeDate = chargeDate, CreatedDate = DateTime.Today, SettlementId = Guid.Empty, AutoChargeId = Guid.Empty, OwnerId = newApartment.OwnerId }; c.Components = new List <ChargeComponent>(); foreach (var costCollection in building.CostCollection) { if (costCollection.BegginingDate > chargeDate || (costCollection.EndingDate.Year > 1901 && costCollection.EndingDate < chargeDate)) { continue; } var group = db.GroupName.FirstOrDefault(x => x.BuildingChargeGroupNameId == costCollection.BuildingChargeGroupNameId); var cc = new ChargeComponent() { ChargeComponentId = Guid.NewGuid(), CostCategoryId = costCollection.BuildingChargeBasisCategoryId, CostDistribution = costCollection.BuildingChargeBasisDistribution, CostPerUnit = costCollection.CostPerUnit, GroupName = group }; double units; switch ((CostDistribution)cc.CostDistribution) { case CostDistribution.PerApartment: units = 1; break; case CostDistribution.PerApartmentTotalArea: units = newApartment.AdditionalArea + newApartment.ApartmentArea; break; case CostDistribution.PerApartmentArea: units = newApartment.ApartmentArea; break; case CostDistribution.PerAdditionalArea: units = newApartment.AdditionalArea; break; case CostDistribution.PerLocators: units = newApartment.Locators; break; default: units = 0; break; } cc.Sum = Math.Round(((Convert.ToDecimal(units) * cc.CostPerUnit) * Convert.ToDecimal(percentage)), 2); c.Components.Add(cc); db.Entry(cc.GroupName).State = EntityState.Unchanged; } if (c.Components != null && c.Components.Count > 0) { db.Charges.Add(c); } chargeDate = (new DateTime(chargeDate.Year, chargeDate.Month, 1)).AddMonths(1); percentage = 1; } db.SaveChanges(); _apartmentLocalCopy = newApartment; } } else { if (!IsValid(this as DependencyObject) || (string.IsNullOrEmpty(SelectedBuildingAddress) || string.IsNullOrEmpty(SelectedOwnerMailAddress) || ApartmentNumber <= 0 || double.Parse(AdditionalArea) < 0 || double.Parse(ApartmentArea) <= 0)) { return; } //Edit Apartment using (var db = new DB.DomenaDBContext()) { var q = db.Apartments.Include(x => x.MeterCollection).Where(x => x.ApartmentId.Equals(_apartmentLocalCopy.ApartmentId)).FirstOrDefault(); q.BoughtDate = BoughtDate.Date; q.AdditionalArea = double.Parse(AdditionalArea); q.ApartmentArea = double.Parse(ApartmentArea); q.ApartmentNumber = ApartmentNumber; q.BuildingId = SelectedBuildingName.BuildingId; q.CreatedDate = DateTime.Now; //q.HasWaterMeter = dc.HasWaterMeter == 0; //q.WaterMeterExp = dc.WaterMeterExp.Date; q.OwnerId = SelectedOwnerName.OwnerId; q.Locators = LocatorsAmount; if (!SelectedOwnerMailAddress.Equals(db.Owners.Where(x => x.OwnerId == _apartmentLocalCopy.OwnerId).Select(x => x.MailAddress))) { q.CorrespondenceAddress = SelectedOwnerMailAddress; } else { q.CorrespondenceAddress = null; } var meters = MeterCollection.Where(x => !x.IsDeleted); foreach (var m in meters) { if (!q.MeterCollection.Any(x => x.MeterId.Equals(m.MeterId))) { q.MeterCollection.Add(m); //var a = db.Buildings.SelectMany(x => x.MeterCollection).FirstOrDefault(x => x.MeterId.Equals(m.MeterTypeParent.MeterId)); db.Entry(m.MeterTypeParent).State = EntityState.Unchanged; } else { var s = q.MeterCollection.FirstOrDefault(x => x.MeterId.Equals(m.MeterId)); s.LegalizationDate = m.LegalizationDate; db.MetersHistories.Add(new MetersHistory { MeterHistoryId = Guid.NewGuid(), Apartment = q, Building = db.Buildings.FirstOrDefault(x => x.BuildingId == q.BuildingId), ApartmentMeter = s, MeterType = s.MeterTypeParent, ModifiedDate = DateTime.Now, NewValue = m.LastMeasure, OldValue = s.LastMeasure }); s.LastMeasure = m.LastMeasure; } } foreach (var m in q.MeterCollection) { if (!meters.Any(x => x.MeterId.Equals(m.MeterId))) { m.IsDeleted = true; } } db.SaveChanges(); } } }
private void SaveDialog(object param) { var newApartment = new Apartment(SelectedApartmentName); newApartment.ApartmentId = Guid.NewGuid(); newApartment.Locators = LocatorsAmount; newApartment.OwnerId = BuyerName.OwnerId; newApartment.CorrespondenceAddress = null; newApartment.BoughtDate = SellDate; var meters = new List <ApartmentMeter>(); foreach (var meter in newApartment.MeterCollection) { var m = new ApartmentMeter() { IsDeleted = meter.IsDeleted, LastMeasure = meter.LastMeasure, LegalizationDate = meter.LegalizationDate, MeterId = Guid.NewGuid(), MeterTypeParent = meter.MeterTypeParent, }; } using (var db = new DB.DomenaDBContext()) { db.Apartments.Add(newApartment); var soldApartment = db.Apartments.FirstOrDefault(x => x.ApartmentId == SelectedApartmentName.ApartmentId); soldApartment.OnSellCreatedApartmentGuid = newApartment.ApartmentId; soldApartment.SoldDate = SellDate; var dateToCompare = new DateTime(SellDate.Year, SellDate.Month, 1); var charges = db.Charges.Include(x => x.Components).Where(x => x.ApartmentId == SelectedApartmentName.ApartmentId && x.ChargeDate >= dateToCompare && !x.IsDeleted); // Charges after sold date to new apartment foreach (var charge in charges) { charge.ApartmentId = newApartment.ApartmentId; charge.OwnerId = newApartment.OwnerId; } charges = charges.Where(x => x.ChargeDate.Month == SellDate.Month && x.ChargeDate.Year == SellDate.Year); var ratio = (double)SellDate.Day / (double)DateTime.DaysInMonth(SellDate.Year, SellDate.Month); // Charges in month of sale split to 2 foreach (var charge in charges) { var soldApartmentCharge = new Charge() { ApartmentId = soldApartment.ApartmentId, AutoChargeId = charge.AutoChargeId, ChargeDate = charge.ChargeDate, ChargeId = Guid.NewGuid(), CreatedDate = DateTime.Today, IsClosed = charge.IsClosed, IsDeleted = charge.IsDeleted, OwnerId = soldApartment.OwnerId, SettlementId = charge.SettlementId, Components = new List <ChargeComponent>(), }; foreach (var cc in charge.Components) { var chargeComponent = new ChargeComponent() { ChargeComponentId = Guid.NewGuid(), CostCategoryId = cc.CostCategoryId, CostDistribution = cc.CostDistribution, CostPerUnit = cc.CostPerUnit, GroupName = cc.GroupName, Sum = Math.Round(cc.Sum * Convert.ToDecimal(ratio), 0), }; soldApartmentCharge.Components.Add(chargeComponent); cc.Sum -= chargeComponent.Sum; } db.Charges.Add(soldApartmentCharge); } db.SaveChanges(); } SwitchPage.SwitchMainPage(new Pages.ApartmentsPage(), this); }