public PaymentsPage(Apartment apartment) { DataContext = this; InitializeCollection(); InitializeLists(); InitializeApartmentsNumbers(); SelectedPayments = new List <PaymentDataGrid>(); InitializeComponent(); GroupByBuilding = true; using (var db = new DB.DomenaDBContext()) { var apar = db.Apartments.FirstOrDefault(x => x.ApartmentId.Equals(apartment.ApartmentId)); SelectedBuildingName = BuildingsNames.FirstOrDefault(x => x.BuildingId.Equals(apar.BuildingId)); SelectedApartmentNumber = apar.ApartmentNumber; SelectedOwnerName = OwnersNames.FirstOrDefault(x => x.OwnerId.Equals(apar.OwnerId)); } }
public ChargesPage(Apartment apartment) { DataContext = this; InitializeCollection(); InitializeCategories(); InitializeLists(); InitializeApartmentsNumbers(); SelectedChargesList = new List<ChargeDataGrid>(); InitializeComponent(); GroupByBuilding = false; ShowClosed = true; using (var db = new DB.DomenaDBContext()) { SelectedBuildingName = BuildingsNames.FirstOrDefault(x => x.BuildingId.Equals(apartment.BuildingId)); SelectedApartmentNumber = ApartmentsNumbers.FirstOrDefault(x => x == apartment.ApartmentNumber); SelectedOwnerName = OwnersNames.FirstOrDefault(x => x.OwnerId.Equals(apartment.OwnerId)); ; } }
public EditPaymentWizard(Payment _payment = null) { DataContext = this; InitializeComponent(); InitializeBuildingList(); InitializeApartmentsNumbers(); _lpc = _payment; if (_payment != null) { CanEdit = false; PaymentRegistrationDate = _payment.PaymentRegistrationDate; PaymentAmount = _payment.PaymentAmount.ToString(); SelectedBuildingName = BuildingsNames.FirstOrDefault(x => x.BuildingId.Equals(_apartmentsOC.FirstOrDefault(a => a.ApartmentId.Equals(_payment.ApartmentId)).BuildingId)); SelectedApartmentNumber = ApartmentsNumbers.FirstOrDefault(x => x.ApartmentId.Equals(_payment.ApartmentId)); OwnerMailAddress = _ownersOC.FirstOrDefault(x => x.OwnerId.Equals(SelectedApartmentNumber.OwnerId)).MailAddress; SelectedGroupName = _groupNamesDB.FirstOrDefault(x => x.BuildingChargeGroupNameId == _payment.ChargeGroup.BuildingChargeGroupNameId); return; } CanEdit = true; PaymentRegistrationDate = DateTime.Today; }
private void PrepareData(Apartment apartment, int year) { var owner = OwnersList.FirstOrDefault(x => x.OwnerId == apartment.OwnerId); var building = BuildingsNames.FirstOrDefault(x => x.BuildingId == apartment.BuildingId); OwnerName = owner.OwnerName; BuildingFullName = building.FullName; ApartmentNumber = apartment.ApartmentNumber.ToString(); Locators = apartment.Locators.ToString(); ApartmentTotalArea = (apartment.AdditionalArea + apartment.ApartmentArea).ToString() + " m2"; using (var db = new DB.DomenaDBContext()) { var apArea = db.Apartments.Where(x => x.BuildingId == apartment.BuildingId && !x.IsDeleted).Select(x => x.ApartmentArea).DefaultIfEmpty(0).Sum(); var addArea = db.Apartments.Where(x => x.BuildingId == apartment.BuildingId && !x.IsDeleted).Select(x => x.AdditionalArea).DefaultIfEmpty(0).Sum(); OwnedPercentage = (Math.Floor(((apartment.AdditionalArea + apartment.ApartmentArea) / (apArea + addArea) * 100) * 100) / 100).ToString() + "%"; var groups = db.Invoices.Where(x => !x.IsDeleted && x.BuildingId == apartment.BuildingId).Select(x => x.InvoiceCategoryId).Distinct().ToList(); var dataGridGroups = new List <InvoiceCategory>(); var settleableGroups = db.BuildingInvoceBindings.Include(x => x.Building).Include(x => x.InvoiceCategory).Where(x => !x.IsDeleted && x.Building.BuildingId == building.BuildingId).ToList(); foreach (var g in groups) { if (settleableGroups.Any(x => x.InvoiceCategory.CategoryId == g)) { dataGridGroups.Add(db.InvoiceCategories.FirstOrDefault(x => x.CategoryId == g)); } } int i = 1; CostsCollection = new ObservableCollection <AnalysisDataGrid>(); // var buildingTotalArea = apArea + addArea; var apartmentsCount = db.Apartments.Where(x => !x.IsDeleted && x.BuildingId == apartment.BuildingId).Count(); var totalLocators = db.Apartments.Where(x => !x.IsDeleted && x.BuildingId == apartment.BuildingId).Select(x => x.Locators).DefaultIfEmpty(0).Sum(); foreach (var inv in dataGridGroups) { var cc = new AnalysisDataGrid() { Id = i.ToString(), Group = inv.CategoryName, TotalCost = Math.Floor(db.Invoices.Where(x => x.InvoiceDate.Year == year && !x.IsDeleted && x.BuildingId == apartment.BuildingId && x.InvoiceCategoryId == inv.CategoryId && x.IsSettled).Select(x => x.CostAmountGross).DefaultIfEmpty(0).Sum() * 100) / 100, IsRepairFund = inv.CategoryId == InvoiceCategory.RepairFundInvoiceCategoryId, }; double scale; switch (settleableGroups.FirstOrDefault(x => x.InvoiceCategory.CategoryId == inv.CategoryId).Distribution) { default: break; case CostDistribution.PerAdditionalArea: scale = Math.Floor(10000 * (apartment.AdditionalArea / addArea)) / 10000; cc.ApartmentCost = Math.Floor(100 * (cc.TotalCost * Convert.ToDecimal(scale))) / 100; break; case CostDistribution.PerApartment: scale = Math.Floor(10000 * (1 / (double)apartmentsCount)) / 10000; cc.ApartmentCost = Math.Floor(100 * (cc.TotalCost * Convert.ToDecimal(scale))) / 100; break; case CostDistribution.PerApartmentArea: scale = Math.Floor(10000 * (apartment.ApartmentArea / apArea)) / 10000; cc.ApartmentCost = Math.Floor(100 * (cc.TotalCost * Convert.ToDecimal(scale))) / 100; break; case CostDistribution.PerApartmentTotalArea: scale = Math.Floor(10000 * ((apartment.ApartmentArea + apartment.AdditionalArea) / buildingTotalArea)) / 10000; cc.ApartmentCost = Math.Floor(100 * (cc.TotalCost * Convert.ToDecimal(scale))) / 100; break; case CostDistribution.PerLocators: scale = Math.Floor(10000 * ((double)apartment.Locators / (double)totalLocators)) / 10000; cc.ApartmentCost = Math.Floor(100 * (cc.TotalCost * Convert.ToDecimal(scale))) / 100; break; } CostsCollection.Add(cc); i++; } CostsCollection.Add(new AnalysisDataGrid() { Id = i.ToString(), Group = "Razem: ", TotalCost = CostsCollection.Where(x => !x.IsRepairFund).Sum(x => x.TotalCost), ApartmentCost = CostsCollection.Where(x => !x.IsRepairFund).Sum(x => x.ApartmentCost), IsRepairFund = false, }); } }