コード例 #1
0
        public List <PaymentListItem> GetPayments(Enrollment currentEnrollment)
        {
            bool isRegistrationRequired = currentEnrollment.Membership.IsRegistrationRequired;
            int  numberPayments         = currentEnrollment.Membership.NumberPayments;

            // Creating 12 empty payments to fill later and show to the user
            DateTime expirationDate = (DateTime)currentEnrollment.StartDate;   // Initializing the expiration date of the first month

            var AllPayments = new List <PaymentListItem>();

            if (isRegistrationRequired)
            {
                AllPayments.Add(new PaymentListItem()
                {
                    IsPaid = false, ExpirationDate = expirationDate, Type = PaymentType.PAYMENT_REGISTRATION, PayingMonth = "0"
                });                                                                                                                                                       // Adding registration payment
            }
            else
            {
                AllPayments.Add(new PaymentListItem()
                {
                    IsPaid = true, ExpirationDate = null, Type = PaymentType.PAYMENT_REGISTRATION, PayingMonth = "0", Notes = "No registration required"
                });                                                                                                                                                                                // Adding registration payment
            }
            for (int i = 1; i <= numberPayments; i++)
            {
                var listItem = new PaymentListItem()
                {
                    PayingMonth    = i.ToString(),
                    IsPaid         = false,
                    ExpirationDate = expirationDate
                };
                expirationDate = expirationDate.AddMonths(1);
                AllPayments.Add(listItem);
            }

            // Obtaining real payments to fill the list of empty payments
            var PaidPayments = db.Payments.Where(p => p.Enrollment.ID == currentEnrollment.ID && p.RenewalNumber == currentEnrollment.RenewalNumber).ToList();

            foreach (var p in PaidPayments)
            {
                int pos = Convert.ToInt32(p.PayingMonth);
                AllPayments.ElementAt(pos).IsPaid = true;
                AllPayments.ElementAt(pos).ID     = p.ID;
                AllPayments.ElementAt(pos).Date   = p.Date;
                AllPayments.ElementAt(pos).Type   = p.Type;
                AllPayments.ElementAt(pos).Amount = p.Amount;
                AllPayments.ElementAt(pos).Notes  = p.Notes;
            }

            return(AllPayments);
        }
コード例 #2
0
        private void FillData()
        {
            Client client = new Client();

            List <OrderProduct>         orderProducts         = new List <OrderProduct>();
            OrderProduct                orderProduct          = new OrderProduct();
            List <OtherProductListItem> otherProductListItems = new List <OtherProductListItem>();
            OtherProductListItem        otherProductListItem  = new OtherProductListItem();

            List <Payment>         payments         = new List <Payment>();
            List <PaymentListItem> paymentListItems = new List <PaymentListItem>();
            PaymentListItem        paymentListItem;

            switch (selectedContract.OrderStatus)
            {
            case 0:    /// New contracts
                LeaseContract selectedLeaseContract = dataBaseAC.LeaseContracts.Find(selectedContract.OrderId);
                client   = dataBaseAC.Clients.Find(selectedLeaseContract.Client_id);
                payments = dataBaseAC.Payments.Where(p => p.Order_id == selectedLeaseContract.Id).ToList();

                creationDateTimeLbl.Content = UnixTimeStampToDateTime(selectedLeaseContract.Create_datetime).ToShortDateString();
                if (selectedLeaseContract.Return_datetime > 0)
                {
                    returnDateTimeLbl.Content = UnixTimeStampToDateTime(selectedLeaseContract.Return_datetime).ToShortDateString();
                }

                this.DataContext = selectedLeaseContract;
                break;

            case 1:    /// Returned lease contracts
                ReturnedLeaseContract returnedLeaseContract = dataBaseAC.ReturnedLeaseContracts.Where(r => r.Order_id == selectedContract.OrderId).FirstOrDefault();
                client   = dataBaseAC.Clients.Find(returnedLeaseContract.Client_id);
                payments = dataBaseAC.Payments.Where(p => p.Order_id == returnedLeaseContract.Order_id).ToList();

                creationDateTimeLbl.Content = UnixTimeStampToDateTime(returnedLeaseContract.Create_datetime).ToShortDateString();
                if (returnedLeaseContract.Return_datetime > 0)
                {
                    returnDateTimeLbl.Content = UnixTimeStampToDateTime(returnedLeaseContract.Return_datetime).ToShortDateString();
                }

                this.DataContext = returnedLeaseContract;
                break;

            case 2:    /// Closed contracts
                ArchiveLeaseContract archiveLeaseContract = dataBaseAC.ArchiveLeaseContracts.Where(c => c.Order_id == selectedContract.OrderId).FirstOrDefault();
                client   = dataBaseAC.Clients.Find(archiveLeaseContract.Client_id);
                payments = dataBaseAC.Payments.Where(p => p.Order_id == archiveLeaseContract.Order_id).ToList();


                creationDateTimeLbl.Content = UnixTimeStampToDateTime(archiveLeaseContract.Create_datetime).ToShortDateString();
                if (archiveLeaseContract.Return_datetime > 0)
                {
                    returnDateTimeLbl.Content = UnixTimeStampToDateTime(archiveLeaseContract.Return_datetime).ToShortDateString();
                }

                this.DataContext = archiveLeaseContract;
                break;
            }

            clientFIOLbl.Content          = client.Surname + " " + client.Name + " " + client.Middle_name;
            clientPhoneNumberLbl.Content  = client.Phone_number;
            clientPassNumberLbl.Content   = client.Pass_number;
            clientPhoneNumber2Lbl.Content = client.Phone_number2;
            clientAddressLbl.Content      = client.Address;
            orderDaysLbl.Content          = selectedContract.UsedDays;

            orderProducts = dataBaseAC.OrderProducts.Where(op => op.Order_id == selectedContract.OrderId).ToList();
            foreach (OrderProduct op in orderProducts)
            {
                otherProductListItem       = new OtherProductListItem();
                otherProductListItem.Name  = dataBaseAC.Products.Find(op.Product_id).Name;
                otherProductListItem.Count = op.Count;
                otherProductListItem.Price = op.Count * op.Price;
                if (dataBaseAC.ReturnProducts.Where(rp => rp.Order_id == op.Order_id && rp.Product_id == op.Product_id).FirstOrDefault() != null)
                {
                    otherProductListItem.Return_count = dataBaseAC.ReturnProducts.Where(rp => rp.Order_id == op.Order_id && rp.Product_id == op.Product_id).FirstOrDefault().Count;
                }
                otherProductListItems.Add(otherProductListItem);
            }
            otherProductListBox.ItemsSource = otherProductListItems;


            foreach (Payment payment in payments)
            {
                paymentListItem             = new PaymentListItem();
                paymentListItem.Amount      = payment.Amount;
                paymentListItem.DateTime    = UnixTimeStampToDateTime(payment.Datetime).ToShortDateString();
                paymentListItem.PaymentType = payment.Payment_type;
                paymentListItems.Add(paymentListItem);
            }
            paymentListBox.ItemsSource = paymentListItems;
        }