Beispiel #1
0
        public JsonResult GetBillData(string billNumber)
        {
            var model      = new BillModel();
            int customerId = 0;
            var billDB     = contextDB.BILL.Where(b => b.NUMBER == billNumber).FirstOrDefault();

            if (billDB != null)
            {
                model.Bill.Id     = billDB.ID;
                model.Bill.Number = billDB.NUMBER;
                model.Bill.Sum    = billDB.SUM;
                model.Bill.Paid   = billDB.PAID;
                model.Bill.Period = CustomizedMethod.GetFullMonthName(billDB);

                customerId = billDB.CUSTOMER_ID;
                var customerDB = contextDB.CUSTOMER.Where(c => c.ID == customerId).FirstOrDefault();

                if (customerDB != null)
                {
                    model.CustomerModel.Customer.Surname = customerDB.SURNAME;
                    model.CustomerModel.Customer.Name    = customerDB.NAME;
                }
            }
            return(Json(model, JsonRequestBehavior.AllowGet));
        }
Beispiel #2
0
        public ActionResult ShowAllBillsForCustomer(int customerId)
        {
            using (var context = new TownUtilityBillSystemEntities())
            {
                var model      = new BillModel();
                var billsDB    = context.BILL.Where(b => b.CUSTOMER_ID == customerId).ToList();
                var customerDB = context.CUSTOMER.Find(customerId);

                if (customerDB != null)
                {
                    GetCustomerDataForView(context, model, customerDB);
                }
                else
                {
                    model.CustomerModel.Customer = null;
                }

                foreach (var b in billsDB)
                {
                    model.Bills.Add(new Bill()
                    {
                        Id = b.ID, Date = b.DATE, Number = b.NUMBER, Period = CustomizedMethod.GetFullMonthName(b), Sum = b.SUM, Paid = b.PAID
                    });
                }

                return(View(model));
            }
        }
Beispiel #3
0
        private void CreateBillModelFromBillList(TownUtilityBillSystemEntities context, BillModel model, List <BILL> billsDB)
        {
            foreach (var b in billsDB)
            {
                Customer customer = new Customer();

                var customerDB = context.CUSTOMER.Where(c => c.ID == b.CUSTOMER_ID).FirstOrDefault();

                CustomerType customerType;
                Address      address;
                GetAddressAndCustomerTypeForCustomer(context, customerDB, out customerType, out address);

                customer.Id      = customerDB.ID;
                customer.Surname = customerDB.SURNAME;
                customer.Name    = customerDB.NAME;

                customer.Address = address;

                model.Bills.Add(new Bill()
                {
                    Id = b.ID, Number = b.NUMBER, Period = CustomizedMethod.GetFullMonthName(b), Date = b.DATE, Sum = b.SUM, Paid = b.PAID, Customer = customer
                });
            }
        }
Beispiel #4
0
        public ActionResult ShowBillPaidInfo(int bill_Id)
        {
            using (var context = new TownUtilityBillSystemEntities())
            {
                var model  = new BillModel();
                var billDB = context.BILL.Find(bill_Id);

                if (billDB != null)
                {
                    model.Bill = new Bill()
                    {
                        Id = billDB.ID, Date = billDB.DATE, Number = billDB.NUMBER, Sum = billDB.SUM, Paid = billDB.PAID, Period = CustomizedMethod.GetFullMonthName(billDB)
                    };
                    var customerDB = context.CUSTOMER.Find(billDB.CUSTOMER_ID);

                    model.CustomerModel.Customer.Surname = customerDB.SURNAME;
                    model.CustomerModel.Customer.Name    = customerDB.NAME;
                }

                return(View(model));
            }
        }
Beispiel #5
0
        public ActionResult PaymentCardForm(int bill_Id)
        {
            using (var context = new TownUtilityBillSystemEntities())
            {
                var model  = new PaymentCardModel();
                var billDB = context.BILL.Find(bill_Id);

                if (billDB != null)
                {
                    model.Bill = new Bill()
                    {
                        Id = billDB.ID, Number = billDB.NUMBER, Date = billDB.DATE, Period = CustomizedMethod.GetFullMonthName(billDB), Sum = billDB.SUM, Paid = billDB.PAID
                    }
                }
                ;

                return(View(model));
            }
        }
Beispiel #6
0
        public ActionResult ShowBill(int bill_Id)
        {
            using (var context = new TownUtilityBillSystemEntities())
            {
                var model = new BillModel();

                int   customerId         = 0;
                float consumedMonthValue = 0;
                float utilityCharges     = 0;

                var billDB = context.BILL.Find(bill_Id);

                if (billDB != null)
                {
                    model.Bill = new Bill()
                    {
                        Id = billDB.ID, Number = billDB.NUMBER, Date = billDB.DATE, Period = CustomizedMethod.GetFullMonthName(billDB), Sum = billDB.SUM, Paid = billDB.PAID
                    };
                    customerId = billDB.CUSTOMER_ID;
                }

                DateTime startDate          = new DateTime();
                DateTime finishDate         = new DateTime();
                DateTime startDateForChart  = new DateTime();
                DateTime finishDateForChart = new DateTime();

                startDate  = Convert.ToDateTime(model.Bill.Period + "-01");
                finishDate = startDate.AddMonths(1);

                int monthDifferenceBillPeriodAndStartUsageChart = 1;
                int presChartYear  = startDate.Year;
                int startChartDay  = 1;
                int prevChartYear  = presChartYear - 1;
                int presChartMonth = startDate.Month;

                float  valueDifference;
                string monthName;

                var customerDB = context.CUSTOMER.Where(c => c.ID == customerId).FirstOrDefault();

                if (customerDB != null)
                {
                    GetCustomerDataForView(context, model, customerDB);
                }
                else
                {
                    model.CustomerModel.Customer = null;
                }

                var metersDB = context.METER.Where(m => m.ADDRESS_ID == model.CustomerModel.Customer.Address.Id).ToList();

                List <MeterItem> meterListDB = new List <MeterItem>();

                foreach (var m in metersDB)
                {
                    List <ChartData> chartData = new List <ChartData>();
                    meterListDB.Clear();

                    startDateForChart  = new DateTime(prevChartYear, presChartMonth + monthDifferenceBillPeriodAndStartUsageChart, startChartDay);
                    finishDateForChart = startDate.AddMonths(1);

                    var meterTypeDB = context.METER_TYPE.Where(mt => mt.ID == m.METER_TYPE_ID).FirstOrDefault();
                    var utilityDB   = context.UTILITY.Where(u => u.ID == meterTypeDB.UTILITY_ID).FirstOrDefault();
                    var unitDB      = context.UNIT.Where(u => u.ID == utilityDB.UNIT_ID).FirstOrDefault();

                    var unit = new Unit()
                    {
                        Id = unitDB.ID, Name = unitDB.NAME
                    };
                    var utility = new Utility()
                    {
                        Id = utilityDB.ID, Name = utilityDB.NAME, Unit = unit, Price = utilityDB.PRICE, ImageIconPath = CustomizedMethod.GetUtilityImage(utilityDB.ID)
                    };

                    if (utilityDB.USAGEFORSTANDARTPRICE != null)
                    {
                        utility.UsageForStandartPrice = (decimal)utilityDB.USAGEFORSTANDARTPRICE;
                    }
                    if (utilityDB.BIGUSAGEPRICE != null)
                    {
                        utility.BigUsagePrice = (decimal)utilityDB.BIGUSAGEPRICE;
                    }

                    if (utility.Id == (int)Utilities.Heating)
                    {
                        GetTemperatureHistory(context, model, m);
                    }

                    var meterItemsDB = (from mi in context.METER_ITEM
                                        where mi.METER_ID == m.ID
                                        select mi).ToList();

                    foreach (var i in meterItemsDB)
                    {
                        meterListDB.Add(new MeterItem()
                        {
                            Id = i.ID, Date = i.DATE, Value = i.VALUE
                        });
                    }

                    if (meterItemsDB.Count != 0)
                    {
                        for (; startDateForChart <= finishDateForChart; startDateForChart = startDateForChart.AddMonths(1))
                        {
                            var startElValue  = meterListDB.Where(ml => ml.Date == startDateForChart.AddMonths(-1)).FirstOrDefault().Value;
                            var finishElValue = meterListDB.Where(ml => ml.Date == startDateForChart).FirstOrDefault().Value;
                            valueDifference = (float)Math.Round(finishElValue - startElValue, 2);

                            if (startDateForChart.Month != 1)
                            {
                                Months month = (Months)(startDateForChart.Month - 1);
                                monthName = month.ToString() + " " + startDateForChart.Year;
                            }
                            else
                            {
                                Months month = Months.December;
                                monthName = month.ToString() + " " + startDateForChart.AddYears(-1).Year;
                            }

                            chartData.Add(new ChartData()
                            {
                                MonthName = monthName, Value = valueDifference
                            });
                        }
                    }

                    var meterType = new MeterType()
                    {
                        Id = meterTypeDB.ID, Name = meterTypeDB.NAME, Utility = utility
                    };

                    var startMeterItem = (from item in context.METER_ITEM
                                          where item.METER_ID == m.ID && item.DATE == startDate
                                          select item).FirstOrDefault();

                    var finishMeterItem = (from item in context.METER_ITEM
                                           where item.METER_ID == m.ID && item.DATE == finishDate
                                           select item).FirstOrDefault();

                    consumedMonthValue = finishMeterItem.VALUE - startMeterItem.VALUE;

                    if (m.METER_TYPE.UTILITY_ID == (int)Utilities.Electricity && consumedMonthValue > (float)m.METER_TYPE.UTILITY.USAGEFORSTANDARTPRICE)
                    {
                        utilityCharges = (float)m.METER_TYPE.UTILITY.USAGEFORSTANDARTPRICE * (float)m.METER_TYPE.UTILITY.PRICE + (consumedMonthValue - (float)m.METER_TYPE.UTILITY.USAGEFORSTANDARTPRICE) * (float)m.METER_TYPE.UTILITY.BIGUSAGEPRICE;
                    }

                    else
                    {
                        utilityCharges = consumedMonthValue * (float)m.METER_TYPE.UTILITY.PRICE;
                    }

                    model.UtilityChargesChartData.Add(new ChartData()
                    {
                        UtilityCharges = (float)Math.Round(utilityCharges, 2)
                    });

                    model.CustomerModel.Meters.Add(
                        new Meter()
                    {
                        Id                 = m.ID,
                        SerialNumber       = m.SERIAL_NUMBER,
                        ReleaseDate        = m.RELEASE_DATE,
                        VarificationDate   = m.VARIFICATION_DATE,
                        MeterType          = meterType,
                        ConsumedMonthValue = consumedMonthValue,
                        ChartData          = chartData
                    });
                }
                return(View(model));
            }
        }