Exemplo n.º 1
0
        /// <summary>
        /// real invoice 1.1.2020 - 31.12.2020
        /// estimated invoices: 1.1.2020 - 31.3.2020, 1.4.2020 - 30.6.2020, 1.7.2020 - 30.9.2020
        /// unestimated invoice: 1.10.2020 - 31.12.2020
        /// </summary>
        /// <param name="realInvoice"></param>
        /// <param name="estimatedInvoices"></param>
        /// <returns></returns>
        public static Model.InvoiceShared CreateUnestimated(this Model.InvoiceShared realInvoice, IEnumerable <Model.InvoiceShared> estimatedInvoices)
        {
            Contract.Requires(realInvoice != null);
            Contract.Requires(estimatedInvoices != null);

            var unestimatedInvoice = new Model.InvoiceShared(realInvoice.Id, estimatedInvoices.LastOrDefault()?.End ?? realInvoice.Start, realInvoice.End)
            {
                Balanced = realInvoice.Balanced
            };

            unestimatedInvoice.GetReadOut().Estimated     = realInvoice.GetReadOut().Estimated;
            unestimatedInvoice.GetReadOut().Real          = realInvoice.GetReadOut().Real;
            unestimatedInvoice.GetConsumption().Estimated = realInvoice.GetConsumption().Estimated; // - estimatedInvoices.Sum(invoice => invoice.GetConsumption().Estimated);
            unestimatedInvoice.GetConsumption().Real      = realInvoice.GetConsumption().Real;      // - estimatedInvoices.Sum(invoice => invoice.GetConsumption().Real);

            foreach (var userInvoice in realInvoice.UserInvoices)
            {
                //var estimatedUserInvoices = estimatedInvoices.GetUserInvoicesByOwner(userInvoice.InvoiceOwner);

                var unestimatedUserInvoice = new Model.UserInvoice(userInvoice.InvoiceOwner, userInvoice.GetReadOutDate(),
                                                                   userInvoice.GetReadOut().Estimated, userInvoice.GetReadOut().Real);

                unestimatedUserInvoice.GetConsumption().Estimated = userInvoice.GetConsumption().Estimated; // - estimatedUserInvoices.Sum(invoice => invoice.GetConsumption().Estimated);
                unestimatedUserInvoice.GetConsumption().Real      = userInvoice.GetConsumption().Real;      // - estimatedUserInvoices.Sum(invoice => invoice.GetConsumption().Real);

                unestimatedInvoice.UserInvoices.Add(unestimatedUserInvoice);
            }

            return(unestimatedInvoice);
        }
Exemplo n.º 2
0
        private static Model.UserInvoice ToUserInvoice(DateTime readOutDate, Model.Wendy1.OldUsers user)
        {
            Contract.Requires(user != null);

            var userInvoice = new Model.UserInvoice(user.User, readOutDate, user.Consumption, user.Consumption);

            userInvoice.GetBasicFee().CleanWaterFee = user.BasicFee;
            userInvoice.GetUsageFee().CleanWaterFee = user.WaterFee;
            userInvoice.GetUsageFee().WasteWaterFee = user.WasteFee;

            return(userInvoice);
        }
Exemplo n.º 3
0
        public void ToInvoiceHistoryTest()
        {
            string wendyXml  = Resource.GetResourceAsString("Wendy.xml");
            var    wendyData = XmlUtil.DeserializeXML <Model.Wendy1.OldWendyFile>(wendyXml, nameSpace: null);

            var invoiceHistory = OldWendyFileConverter.ToInvoiceHistory(wendyData);

            Assert.AreEqual(1, invoiceHistory.MainMeterConfigHistory.MeterConfigs.Count);
            Assert.AreEqual(0, invoiceHistory.MainMeterConfigHistory.MeterConfigs[0].Id);
            Assert.AreEqual(new DateTime(), invoiceHistory.MainMeterConfigHistory.MeterConfigs[0].Start);
            Assert.AreEqual(null, invoiceHistory.MainMeterConfigHistory.MeterConfigs[0].End);
            Assert.AreEqual(0U, invoiceHistory.MainMeterConfigHistory.MeterConfigs[0].StartReadOut);
            Assert.AreEqual(null, invoiceHistory.MainMeterConfigHistory.MeterConfigs[0].EndReadOut);

            Assert.AreEqual(2, invoiceHistory.UserMeterConfigHistory.Count);
            Assert.AreEqual("Apartment B", invoiceHistory.UserMeterConfigHistory[0].MeterUser);
            Assert.AreEqual(1, invoiceHistory.UserMeterConfigHistory[0].MeterConfigs.Count);
            Assert.AreEqual(0, invoiceHistory.UserMeterConfigHistory[0].MeterConfigs[0].Id);
            Assert.AreEqual(new DateTime(), invoiceHistory.UserMeterConfigHistory[0].MeterConfigs[0].Start);
            Assert.AreEqual(null, invoiceHistory.UserMeterConfigHistory[0].MeterConfigs[0].End);
            Assert.AreEqual(0U, invoiceHistory.UserMeterConfigHistory[0].MeterConfigs[0].StartReadOut);
            Assert.AreEqual(null, invoiceHistory.UserMeterConfigHistory[0].MeterConfigs[0].EndReadOut);

            Assert.AreEqual(4, invoiceHistory.FeeConfigHistory.Count);
            Assert.AreEqual(new DateTime(), invoiceHistory.FeeConfigHistory[0].Start);
            Assert.AreEqual(new DateTime(2007, 12, 31), invoiceHistory.FeeConfigHistory[0].End);
            Assert.AreEqual(1.04m, invoiceHistory.FeeConfigHistory[0].MonthlyUsageFee.CleanWaterFee);
            Assert.AreEqual(1.34m, invoiceHistory.FeeConfigHistory[0].MonthlyUsageFee.WasteWaterFee);
            Assert.AreEqual(22, invoiceHistory.FeeConfigHistory[0].VAT);
            Assert.AreEqual(false, invoiceHistory.FeeConfigHistory[0].VATIncludedIntoMonthlyFees);

            Assert.AreEqual(14, invoiceHistory.Invoices.Count);
            {
                Model.InvoiceShared invoice = invoiceHistory.Invoices[0];
                Assert.AreEqual(0, invoice.Id);
                Assert.AreEqual(new DateTime(2007, 08, 18), invoice.Start);
                Assert.AreEqual(new DateTime(2007, 12, 19), invoice.End);
                Assert.AreEqual(true, invoice.Balanced);
                Assert.AreEqual(new DateTime(2007, 12, 19), invoice.GetReadOutDate());
                Assert.AreEqual(76U, invoice.GetReadOut().Estimated);
                Assert.AreEqual(76U, invoice.GetReadOut().Real);
                Assert.AreEqual(0U, invoice.GetConsumption().Estimated);
                Assert.AreEqual(0U, invoice.GetConsumption().Real);
                Assert.AreEqual(11.24m, invoice.GetBasicFee().CleanWaterFee);
                Assert.AreEqual(0m, invoice.GetBasicFee().WasteWaterFee);
                Assert.AreEqual(79.04m, invoice.GetUsageFee().CleanWaterFee);
                Assert.AreEqual(101.84m, invoice.GetUsageFee().WasteWaterFee);
            }
            {
                Model.InvoiceShared invoice = invoiceHistory.Invoices[1];
                Assert.AreEqual(1, invoice.Id);
                Assert.AreEqual(new DateTime(2007, 12, 20), invoice.Start);
                Assert.AreEqual(new DateTime(2007, 12, 31), invoice.End);
                Assert.AreEqual(false, invoice.Balanced);
                Assert.AreEqual(new DateTime(2007, 12, 31), invoice.GetReadOutDate());
                Assert.AreEqual(91U, invoice.GetReadOut().Estimated);
                Assert.AreEqual(91U, invoice.GetReadOut().Real);
                Assert.AreEqual(18U, invoice.GetConsumption().Estimated);
                Assert.AreEqual(0U, invoice.GetConsumption().Real);
                Assert.AreEqual(1.09m, invoice.GetBasicFee().CleanWaterFee);
                Assert.AreEqual(0m, invoice.GetBasicFee().WasteWaterFee);
                Assert.AreEqual(18.72m, invoice.GetUsageFee().CleanWaterFee);
                Assert.AreEqual(24.12m, invoice.GetUsageFee().WasteWaterFee);
            }

            Assert.AreEqual(2, invoiceHistory.Invoices[0].UserInvoices.Count);
            {
                Model.UserInvoice userInvoice = invoiceHistory.Invoices[0].UserInvoices[1];
                Assert.AreEqual("Apartment A", userInvoice.InvoiceOwner);
                Assert.AreEqual(new DateTime(2007, 12, 19), userInvoice.GetReadOutDate());
                Assert.AreEqual(48U, userInvoice.GetReadOut().Estimated);
                Assert.AreEqual(48U, userInvoice.GetReadOut().Real);
                Assert.AreEqual(0U, userInvoice.GetConsumption().Estimated);
                Assert.AreEqual(0U, userInvoice.GetConsumption().Real);
                Assert.AreEqual(5.62m, userInvoice.GetBasicFee().CleanWaterFee);
                Assert.AreEqual(0m, userInvoice.GetBasicFee().WasteWaterFee);
                Assert.AreEqual(49.92m, userInvoice.GetUsageFee().CleanWaterFee);
                Assert.AreEqual(64.32m, userInvoice.GetUsageFee().WasteWaterFee);
            }

            Assert.AreEqual(2, invoiceHistory.Invoices[1].UserInvoices.Count);
            {
                Model.UserInvoice userInvoice = invoiceHistory.Invoices[1].UserInvoices[0];
                Assert.AreEqual("Apartment B", userInvoice.InvoiceOwner);
                Assert.AreEqual(new DateTime(2007, 12, 31), userInvoice.GetReadOutDate());
                Assert.AreEqual(34U, userInvoice.GetReadOut().Estimated);
                Assert.AreEqual(34U, userInvoice.GetReadOut().Real);
                Assert.AreEqual(0U, userInvoice.GetConsumption().Estimated);
                Assert.AreEqual(0U, userInvoice.GetConsumption().Real);
                Assert.AreEqual(0.55m, userInvoice.GetBasicFee().CleanWaterFee);
                Assert.AreEqual(0m, userInvoice.GetBasicFee().WasteWaterFee);
                Assert.AreEqual(8.32m, userInvoice.GetUsageFee().CleanWaterFee);
                Assert.AreEqual(10.72m, userInvoice.GetUsageFee().WasteWaterFee);
            }
        }