Ejemplo n.º 1
0
        public void TestVFJan13()
        {
            // Test scenario: Viktors Farmor booking 13 for sale VF Jan with Estrella Chimborazo
            ICustomer viktorsFarmor      = customerController.CreateCustomer(CustomerType.Bureau, "", "Viktors Farmor");
            ISupplier estrellaChimborazo = supplierController.CreateSupplier("Estrella Chimborazo", "",
                                                                             SupplierType.Restaurant);

            // PaymentRule to use for the booking
            supplierController.AddPaymentRule(estrellaChimborazo, viktorsFarmor, BookingType.Group, 100, -1,
                                              BaseDate.StartDate, PaymentType.Full);

            // Dummy PaymentRule (must not be applied)
            supplierController.AddPaymentRule(estrellaChimborazo, viktorsFarmor, BookingType.FIT, 100, 14,
                                              BaseDate.EndDate, PaymentType.Full);

            IBooking booking = bookingController.CreateBooking(estrellaChimborazo, viktorsFarmor, "VF Jan", 13,
                                                               new DateTime(2014, 01, 14), new DateTime(2014, 01, 14));

            booking.Type              = BookingType.Group;
            booking.IVAExempt         = 0m;
            booking.IVASubject        = 378m;
            booking.ProductRetention  = 2m;
            booking.SupplierRetention = 70m;

            bookingController.CalculatePaymentsForBooking(booking);

            // Check that TransferAmount and IVA match real world data
            string expectedTransferAmount = "384.05";
            string expectedIVA            = "45.36";

            Assert.AreEqual(expectedTransferAmount, booking.TransferAmount.ToString("N2", culture.NumberFormat));
            Assert.AreEqual(expectedIVA, booking.IVA.ToString("N2", culture.NumberFormat));

            // Check that correct number of payments was created
            int             expectedNumberOfPayments = 1;
            List <IPayment> createdPayments          = paymentController.ReadAllPayments();

            Assert.AreEqual(expectedNumberOfPayments, createdPayments.Count);

            // Check that Payment stats set by PaymentRules match real world data
            IPayment payment           = createdPayments[0];
            string   expectedDueAmount = "384.05";
            DateTime expectedDueDate   = new DateTime(2014, 01, 13);

            Assert.AreEqual(expectedDueAmount, payment.DueAmount.ToString("N2", culture.NumberFormat));
            Assert.AreEqual(expectedDueDate, payment.DueDate);
        }
        private void saveButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (supplierTabControl.IsSelected)
                {
                    if (selectedSupplier == null)
                    {
                        string       name = nameTextBox.Text;
                        SupplierType type = (SupplierType)supplierTypeComboBox.SelectedItem;
                        string       note = noteTextBox.Text;

                        ISupplier supplier = supplierController.CreateSupplier(name, note, type);
                        supplier.AccountName = accountNameTextBox.Text;
                        supplier.AccountNo   = accountNoTextBox.Text;
                        supplier.AccountType = (AccountType)accountTypeComboBox.SelectedItem;
                        supplier.Bank        = bankTextBox.Text;
                        supplier.OwnerId     = ownerIdTextBox.Text;

                        supplierController.UpdateSupplier(supplier);
                        refreshDataGrid();
                        suppliersDataGrid.SelectedItem = null;
                        setValuesInTextBoxes();
                    }
                    else
                    {
                        int currentIndex = suppliersDataGrid.SelectedIndex;

                        selectedSupplier.Name        = nameTextBox.Text;
                        selectedSupplier.Type        = (SupplierType)supplierTypeComboBox.SelectedItem;
                        selectedSupplier.Note        = noteTextBox.Text;
                        selectedSupplier.AccountName = accountNameTextBox.Text;
                        selectedSupplier.AccountNo   = accountNoTextBox.Text;
                        selectedSupplier.AccountType = (AccountType)accountTypeComboBox.SelectedItem;
                        selectedSupplier.Bank        = bankTextBox.Text;
                        selectedSupplier.OwnerId     = ownerIdTextBox.Text;

                        supplierController.UpdateSupplier(selectedSupplier);
                        refreshDataGrid();
                        suppliersDataGrid.SelectedIndex = currentIndex;
                    }
                }
                else if (paymentRuleTabControl.IsSelected)
                {
                    ICustomer customer = null;

                    foreach (ICustomer theCustomer in customerController.ReadAllCustomers())
                    {
                        if (theCustomer.Name == customerTextBox.Text)
                        {
                            customer = theCustomer;
                        }
                    }

                    ISupplier   supplier    = selectedSupplier;
                    BookingType bookingType = (BookingType)bookingTypeComboBox.SelectedItem;
                    decimal     percentage;
                    decimal.TryParse(percentageTextBox.Text, NumberStyles.Any, culture, out percentage);
                    int daysOffSet;
                    int.TryParse(daysOffsetTextBox.Text, out daysOffSet);
                    BaseDate    baseDate    = (BaseDate)baseDateComboBox.SelectedItem;
                    PaymentType paymentType = (PaymentType)paymentTypeComboBox.SelectedItem;


                    supplierController.AddPaymentRule(supplier, customer, bookingType, percentage, daysOffSet, baseDate,
                                                      paymentType);
                    refreshPaymentRuleDataGrid();
                    setPaymentRuleValuesInTextBoxes();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }