Ejemplo n.º 1
0
        public static DiscountAdjustmentBuilder WithPercentageDefaults(this DiscountAdjustmentBuilder @this)
        {
            var faker = @this.Session.Faker();

            @this.WithPercentage(decimal.Round(faker.Random.Decimal(1, 5), 2));
            @this.WithDescription(faker.Lorem.Sentence());

            return(@this);
        }
Ejemplo n.º 2
0
        public void EditForSalesOrder()
        {
            this.salesOrderListPage = this.Sidenav.NavigateToSalesOrders();

            var salesOrder = new SalesOrders(this.Session).Extent().First;

            salesOrder.AddOrderAdjustment(new DiscountAdjustmentBuilder(this.Session).WithAmountDefaults().Build());

            this.Session.Derive();
            this.Session.Commit();

            var before = new OrderAdjustments(this.Session).Extent().ToArray();

            var expected = new DiscountAdjustmentBuilder(this.Session).WithAmountDefaults().Build();

            var discountAdjustment = salesOrder.OrderAdjustments.First();
            var id = discountAdjustment.Id;

            this.Session.Derive();

            var expectedAmount      = expected.Amount;
            var expectedDescription = expected.Description;

            this.salesOrderListPage.Table.DefaultAction(salesOrder);
            var salesOrderOverview      = new SalesOrderOverviewComponent(this.salesOrderListPage.Driver);
            var adjustmentOverviewPanel = salesOrderOverview.OrderadjustmentOverviewPanel.Click();

            adjustmentOverviewPanel.Table.DefaultAction(discountAdjustment);

            var adjustmentEdit = new OrderAdjustmentEditComponent(this.Driver);

            adjustmentEdit.Amount.Set(expected.Amount.ToString());
            adjustmentEdit.Description.Set(expected.Description);

            this.Session.Rollback();
            adjustmentEdit.SAVE.Click();

            this.Driver.WaitForAngular();
            this.Session.Rollback();

            var after = new OrderAdjustments(this.Session).Extent().ToArray();

            var actual = (DiscountAdjustment)this.Session.Instantiate(id);

            Assert.Equal(after.Length, before.Length);

            Assert.Equal(expectedAmount, actual.Amount);
            Assert.Equal(expectedDescription, actual.Description);
        }
Ejemplo n.º 3
0
        public void GivenDiscountAdjustment_WhenDeriving_ThenRequiredRelationsMustExist()
        {
            var builder = new DiscountAdjustmentBuilder(this.DatabaseSession);
            builder.Build();

            Assert.IsTrue(this.DatabaseSession.Derive().HasErrors);

            this.DatabaseSession.Rollback();

            builder.WithAmount(1);
            builder.Build();

            Assert.IsFalse(this.DatabaseSession.Derive().HasErrors);

            builder.WithPercentage(1);
            builder.Build();

            Assert.IsTrue(this.DatabaseSession.Derive().HasErrors);
        }
        public void CreatePercentageForProductQuote()
        {
            this.quoteListPage = this.Sidenav.NavigateToProductQuotes();

            var quote = new ProductQuotes(this.Session).Extent().First;

            var before = new DiscountAdjustments(this.Session).Extent().ToArray();

            var expected = new DiscountAdjustmentBuilder(this.Session).WithPercentageDefaults().Build();

            quote.AddOrderAdjustment(expected);

            this.Session.Derive();

            Assert.True(expected.ExistPercentage);
            Assert.True(expected.ExistDescription);

            var expectedPercentage  = expected.Percentage;
            var expectedDescription = expected.Description;

            this.quoteListPage.Table.DefaultAction(quote);
            var discountAdjustmentCreate = new ProductQuoteOverviewComponent(this.quoteListPage.Driver).OrderadjustmentOverviewPanel.Click().CreateDiscountAdjustment();

            discountAdjustmentCreate
            .Percentage.Set(expectedPercentage.ToString())
            .Description.Set(expectedDescription);

            this.Session.Rollback();
            discountAdjustmentCreate.SAVE.Click();

            this.Driver.WaitForAngular();
            this.Session.Rollback();

            var after = new DiscountAdjustments(this.Session).Extent().ToArray();

            Assert.Equal(after.Length, before.Length + 1);

            var actual = after.Except(before).First();

            Assert.Equal(expectedPercentage, actual.Percentage);
            Assert.Equal(expectedDescription, actual.Description);
        }
        public void CreateAmountForPurchaseInvoice()
        {
            this.purchaseInvoiceListPage = this.Sidenav.NavigateToPurchaseInvoices();

            var purchaseInvoice = new PurchaseInvoices(this.Session).Extent().First;

            var before = new DiscountAdjustments(this.Session).Extent().ToArray();

            var expected = new DiscountAdjustmentBuilder(this.Session).WithAmountDefaults().Build();

            purchaseInvoice.AddOrderAdjustment(expected);

            this.Session.Derive();

            Assert.True(expected.ExistAmount);
            Assert.True(expected.ExistDescription);

            var expectedAmount      = expected.Amount;
            var expectedDescription = expected.Description;

            this.purchaseInvoiceListPage.Table.DefaultAction(purchaseInvoice);
            var discountAdjustmentCreate = new PurchaseInvoiceOverviewComponent(this.purchaseInvoiceListPage.Driver).OrderadjustmentOverviewPanel.Click().CreateDiscountAdjustment();

            discountAdjustmentCreate
            .Amount.Set(expectedAmount.ToString())
            .Description.Set(expectedDescription);

            this.Session.Rollback();
            discountAdjustmentCreate.SAVE.Click();

            this.Driver.WaitForAngular();
            this.Session.Rollback();

            var after = new DiscountAdjustments(this.Session).Extent().ToArray();

            Assert.Equal(after.Length, before.Length + 1);

            var actual = after.Except(before).First();

            Assert.Equal(expectedAmount, actual.Amount);
            Assert.Equal(expectedDescription, actual.Description);
        }
        public void GivenDiscountAdjustment_WhenDeriving_ThenRequiredRelationsMustExist()
        {
            var builder = new DiscountAdjustmentBuilder(this.Session);

            builder.Build();

            Assert.True(this.Session.Derive(false).HasErrors);

            this.Session.Rollback();

            builder.WithAmount(1);
            builder.Build();

            Assert.False(this.Session.Derive(false).HasErrors);

            builder.WithPercentage(1);
            builder.Build();

            Assert.True(this.Session.Derive(false).HasErrors);
        }
Ejemplo n.º 7
0
        public void BaseInvoice(CustomerShipmentInvoice method)
        {
            if (this.ShipmentState.Equals(new ShipmentStates(this.Strategy.Session).Shipped) &&
                Equals(this.Store.BillingProcess, new BillingProcesses(this.Strategy.Session).BillingForShipmentItems))
            {
                var invoiceByOrder = new Dictionary <SalesOrder, SalesInvoice>();
                var costsInvoiced  = false;

                foreach (ShipmentItem shipmentItem in this.ShipmentItems)
                {
                    foreach (OrderShipment orderShipment in shipmentItem.OrderShipmentsWhereShipmentItem)
                    {
                        var salesOrder = orderShipment.OrderItem.OrderWhereValidOrderItem as SalesOrder;

                        if (!invoiceByOrder.TryGetValue(salesOrder, out var salesInvoice))
                        {
                            salesInvoice = new SalesInvoiceBuilder(this.Strategy.Session)
                                           .WithStore(salesOrder.Store)
                                           .WithBilledFrom(salesOrder.TakenBy)
                                           .WithAssignedBilledFromContactMechanism(salesOrder.DerivedTakenByContactMechanism)
                                           .WithBilledFromContactPerson(salesOrder.TakenByContactPerson)
                                           .WithBillToCustomer(salesOrder.BillToCustomer)
                                           .WithAssignedBillToContactMechanism(salesOrder.DerivedBillToContactMechanism)
                                           .WithBillToContactPerson(salesOrder.BillToContactPerson)
                                           .WithBillToEndCustomer(salesOrder.BillToEndCustomer)
                                           .WithAssignedBillToEndCustomerContactMechanism(salesOrder.DerivedBillToEndCustomerContactMechanism)
                                           .WithBillToEndCustomerContactPerson(salesOrder.BillToEndCustomerContactPerson)
                                           .WithShipToCustomer(salesOrder.ShipToCustomer)
                                           .WithAssignedShipToAddress(salesOrder.DerivedShipToAddress)
                                           .WithShipToContactPerson(salesOrder.ShipToContactPerson)
                                           .WithShipToEndCustomer(salesOrder.ShipToEndCustomer)
                                           .WithAssignedShipToEndCustomerAddress(salesOrder.DerivedShipToEndCustomerAddress)
                                           .WithShipToEndCustomerContactPerson(salesOrder.ShipToEndCustomerContactPerson)
                                           .WithInvoiceDate(this.Session().Now())
                                           .WithSalesChannel(salesOrder.SalesChannel)
                                           .WithSalesInvoiceType(new SalesInvoiceTypes(this.Strategy.Session).SalesInvoice)
                                           .WithAssignedVatRegime(salesOrder.DerivedVatRegime)
                                           .WithAssignedIrpfRegime(salesOrder.DerivedIrpfRegime)
                                           .WithCustomerReference(salesOrder.CustomerReference)
                                           .WithAssignedPaymentMethod(this.PaymentMethod)
                                           .Build();

                            invoiceByOrder.Add(salesOrder, salesInvoice);

                            foreach (OrderAdjustment orderAdjustment in salesOrder.OrderAdjustments)
                            {
                                OrderAdjustment newAdjustment = null;
                                if (orderAdjustment.GetType().Name.Equals(typeof(DiscountAdjustment).Name))
                                {
                                    newAdjustment = new DiscountAdjustmentBuilder(this.Session()).Build();
                                }

                                if (orderAdjustment.GetType().Name.Equals(typeof(SurchargeAdjustment).Name))
                                {
                                    newAdjustment = new SurchargeAdjustmentBuilder(this.Session()).Build();
                                }

                                if (orderAdjustment.GetType().Name.Equals(typeof(Fee).Name))
                                {
                                    newAdjustment = new FeeBuilder(this.Session()).Build();
                                }

                                if (orderAdjustment.GetType().Name.Equals(typeof(ShippingAndHandlingCharge).Name))
                                {
                                    newAdjustment = new ShippingAndHandlingChargeBuilder(this.Session()).Build();
                                }

                                if (orderAdjustment.GetType().Name.Equals(typeof(MiscellaneousCharge).Name))
                                {
                                    newAdjustment = new MiscellaneousChargeBuilder(this.Session()).Build();
                                }

                                newAdjustment.Amount ??= orderAdjustment.Amount;
                                newAdjustment.Percentage ??= orderAdjustment.Percentage;
                                salesInvoice.AddOrderAdjustment(newAdjustment);
                            }

                            if (!costsInvoiced)
                            {
                                var costs = this.BaseOnDeriveShippingAndHandlingCharges();
                                if (costs > 0)
                                {
                                    salesInvoice.AddOrderAdjustment(new ShippingAndHandlingChargeBuilder(this.Strategy.Session).WithAmount(costs).Build());
                                    costsInvoiced = true;
                                }
                            }

                            foreach (SalesTerm salesTerm in salesOrder.SalesTerms)
                            {
                                if (salesTerm.GetType().Name == typeof(IncoTerm).Name)
                                {
                                    salesInvoice.AddSalesTerm(new IncoTermBuilder(this.Strategy.Session)
                                                              .WithTermType(salesTerm.TermType)
                                                              .WithTermValue(salesTerm.TermValue)
                                                              .WithDescription(salesTerm.Description)
                                                              .Build());
                                }

                                if (salesTerm.GetType().Name == typeof(InvoiceTerm).Name)
                                {
                                    salesInvoice.AddSalesTerm(new InvoiceTermBuilder(this.Strategy.Session)
                                                              .WithTermType(salesTerm.TermType)
                                                              .WithTermValue(salesTerm.TermValue)
                                                              .WithDescription(salesTerm.Description)
                                                              .Build());
                                }

                                if (salesTerm.GetType().Name == typeof(OrderTerm).Name)
                                {
                                    salesInvoice.AddSalesTerm(new OrderTermBuilder(this.Strategy.Session)
                                                              .WithTermType(salesTerm.TermType)
                                                              .WithTermValue(salesTerm.TermValue)
                                                              .WithDescription(salesTerm.Description)
                                                              .Build());
                                }
                            }
                        }

                        var amountAlreadyInvoiced = shipmentItem.ShipmentItemBillingsWhereShipmentItem.Sum(v => v.Amount);
                        var leftToInvoice         = (orderShipment.OrderItem.QuantityOrdered * orderShipment.OrderItem.AssignedUnitPrice) - amountAlreadyInvoiced;

                        if (leftToInvoice > 0)
                        {
                            if (orderShipment.OrderItem is SalesOrderItem salesOrderItem)
                            {
                                var invoiceItem = new SalesInvoiceItemBuilder(this.Strategy.Session)
                                                  .WithInvoiceItemType(new InvoiceItemTypes(this.Strategy.Session).ProductItem)
                                                  .WithProduct(salesOrderItem.Product)
                                                  .WithQuantity(orderShipment.Quantity)
                                                  .WithAssignedUnitPrice(salesOrderItem.UnitPrice)
                                                  .WithAssignedVatRegime(salesOrderItem.AssignedVatRegime)
                                                  .WithDescription(salesOrderItem.Description)
                                                  .WithInternalComment(salesOrderItem.InternalComment)
                                                  .WithMessage(salesOrderItem.Message)
                                                  .Build();

                                salesInvoice.AddSalesInvoiceItem(invoiceItem);

                                new ShipmentItemBillingBuilder(this.Strategy.Session)
                                .WithQuantity(shipmentItem.Quantity)
                                .WithAmount(leftToInvoice)
                                .WithShipmentItem(shipmentItem)
                                .WithInvoiceItem(invoiceItem)
                                .Build();
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 8
0
        public void GivenInvoiceItemWithDiscountPercentageAndItemDiscountPercentage_WhenDeriving_ThenExtraDiscountIsCalculated()
        {
            const decimal quantity = 3;
            const decimal percentage = 5;
            const decimal adjustmentPerc = 10;

            var discountAdjustment = new DiscountAdjustmentBuilder(this.DatabaseSession).WithPercentage(adjustmentPerc).Build();

            new DiscountComponentBuilder(this.DatabaseSession)
                .WithSpecifiedFor(this.internalOrganisation)
                .WithDescription("discount good for sales type")
                .WithSalesChannel(new SalesChannels(this.DatabaseSession).EmailChannel)
                .WithProduct(this.good)
                .WithPercentage(percentage)
                .WithFromDate(DateTime.UtcNow.AddMinutes(-1))
                .WithThroughDate(DateTime.UtcNow.AddYears(1).AddDays(-1))
                .Build();

            this.DatabaseSession.Derive(true);
            this.DatabaseSession.Commit();

            this.InstantiateObjects(this.DatabaseSession);

            this.invoice.SalesChannel = new SalesChannels(this.DatabaseSession).EmailChannel;

            var item1 = new SalesInvoiceItemBuilder(this.DatabaseSession)
                .WithSalesInvoiceItemType(new SalesInvoiceItemTypes(this.DatabaseSession).ProductItem)
                .WithProduct(this.good)
                .WithQuantity(quantity)
                .WithDiscountAdjustment(discountAdjustment)
                .Build();

            this.invoice.AddSalesInvoiceItem(item1);

            this.DatabaseSession.Derive(true);

            var discount = decimal.Round((this.currentGood1BasePrice.Price * percentage) / 100, 2);
            var discountedprice = this.currentGood1BasePrice.Price - discount;
            var adjustmentPercentage = discountAdjustment.Percentage.HasValue ? discountAdjustment.Percentage.Value : 0;
            discount += decimal.Round((discountedprice * adjustmentPercentage) / 100, 2);

            Assert.AreEqual(this.currentGood1BasePrice.Price, item1.UnitBasePrice);
            Assert.AreEqual(discount, item1.UnitDiscount);
            Assert.AreEqual(0, item1.UnitSurcharge);
            Assert.AreEqual(this.currentGood1BasePrice.Price - discount, item1.CalculatedUnitPrice);
            Assert.AreEqual(this.goodPurchasePrice.Price, item1.UnitPurchasePrice);

            Assert.AreEqual(decimal.Round(((item1.UnitBasePrice / this.goodPurchasePrice.Price) - 1) * 100, 2), item1.InitialMarkupPercentage);
            Assert.AreEqual(decimal.Round(((item1.CalculatedUnitPrice / this.goodPurchasePrice.Price) - 1) * 100, 2), item1.MaintainedMarkupPercentage);
            Assert.AreEqual(decimal.Round(((item1.UnitBasePrice - this.goodPurchasePrice.Price) / item1.UnitBasePrice) * 100, 2), item1.InitialProfitMargin);
            Assert.AreEqual(decimal.Round(((item1.CalculatedUnitPrice - this.goodPurchasePrice.Price) / item1.CalculatedUnitPrice) * 100, 2), item1.MaintainedProfitMargin);
        }
Ejemplo n.º 9
0
        public void BaseCreateSalesInvoice(PurchaseInvoiceCreateSalesInvoice method)
        {
            var salesInvoice = new SalesInvoiceBuilder(this.Strategy.Session)
                               .WithPurchaseInvoice(this)
                               .WithBilledFrom(this.BilledTo)
                               .WithBilledFromContactPerson(this.BilledToContactPerson)
                               .WithBillToCustomer(this.BillToEndCustomer)
                               .WithAssignedBillToContactMechanism(this.DerivedBillToEndCustomerContactMechanism)
                               .WithBillToContactPerson(this.BillToEndCustomerContactPerson)
                               .WithShipToCustomer(this.ShipToEndCustomer)
                               .WithAssignedShipToAddress(this.DerivedShipToEndCustomerAddress)
                               .WithShipToContactPerson(this.ShipToEndCustomerContactPerson)
                               .WithDescription(this.Description)
                               .WithInvoiceDate(this.Session().Now())
                               .WithSalesInvoiceType(new SalesInvoiceTypes(this.Strategy.Session).SalesInvoice)
                               .WithCustomerReference(this.CustomerReference)
                               .WithAssignedPaymentMethod(this.DerivedBillToCustomerPaymentMethod)
                               .WithComment(this.Comment)
                               .WithInternalComment(this.InternalComment)
                               .Build();

            foreach (OrderAdjustment orderAdjustment in this.OrderAdjustments)
            {
                OrderAdjustment newAdjustment = null;
                if (orderAdjustment.GetType().Name.Equals(typeof(DiscountAdjustment).Name))
                {
                    newAdjustment = new DiscountAdjustmentBuilder(this.Session()).Build();
                }

                if (orderAdjustment.GetType().Name.Equals(typeof(SurchargeAdjustment).Name))
                {
                    newAdjustment = new SurchargeAdjustmentBuilder(this.Session()).Build();
                }

                if (orderAdjustment.GetType().Name.Equals(typeof(Fee).Name))
                {
                    newAdjustment = new FeeBuilder(this.Session()).Build();
                }

                if (orderAdjustment.GetType().Name.Equals(typeof(ShippingAndHandlingCharge).Name))
                {
                    newAdjustment = new ShippingAndHandlingChargeBuilder(this.Session()).Build();
                }

                if (orderAdjustment.GetType().Name.Equals(typeof(MiscellaneousCharge).Name))
                {
                    newAdjustment = new MiscellaneousChargeBuilder(this.Session()).Build();
                }

                newAdjustment.Amount ??= orderAdjustment.Amount;
                newAdjustment.Percentage ??= orderAdjustment.Percentage;
                salesInvoice.AddOrderAdjustment(newAdjustment);
            }

            foreach (PurchaseInvoiceItem purchaseInvoiceItem in this.PurchaseInvoiceItems)
            {
                var invoiceItem = new SalesInvoiceItemBuilder(this.Strategy.Session)
                                  .WithInvoiceItemType(purchaseInvoiceItem.InvoiceItemType)
                                  .WithAssignedUnitPrice(purchaseInvoiceItem.AssignedUnitPrice)
                                  .WithProduct(purchaseInvoiceItem.Part as UnifiedGood)
                                  .WithSerialisedItem(purchaseInvoiceItem.SerialisedItem)
                                  .WithNextSerialisedItemAvailability(new SerialisedItemAvailabilities(this.Session()).Sold)
                                  .WithQuantity(purchaseInvoiceItem.Quantity)
                                  .WithComment(purchaseInvoiceItem.Comment)
                                  .WithInternalComment(purchaseInvoiceItem.InternalComment)
                                  .Build();

                salesInvoice.AddSalesInvoiceItem(invoiceItem);
            }

            var internalOrganisation = (InternalOrganisation)salesInvoice.BilledFrom;

            if (!internalOrganisation.ActiveCustomers.Contains(salesInvoice.BillToCustomer))
            {
                new CustomerRelationshipBuilder(this.Strategy.Session)
                .WithCustomer(salesInvoice.BillToCustomer)
                .WithInternalOrganisation(internalOrganisation)
                .Build();
            }

            this.AddDeniedPermission(new Permissions(this.Strategy.Session).Get(this.Meta.ObjectType, this.Meta.CreateSalesInvoice, Operations.Execute));
        }
Ejemplo n.º 10
0
        public void BaseInvoice(PurchaseOrderInvoice method)
        {
            if (this.CanInvoice)
            {
                var purchaseInvoice = new PurchaseInvoiceBuilder(this.Strategy.Session)
                                      .WithBilledFrom(this.TakenViaSupplier)
                                      .WithAssignedBilledFromContactMechanism(this.DerivedTakenViaContactMechanism)
                                      .WithBilledFromContactPerson(this.TakenViaContactPerson)
                                      .WithBilledTo(this.OrderedBy)
                                      .WithBilledToContactPerson(this.BillToContactPerson)
                                      .WithDescription(this.Description)
                                      .WithInvoiceDate(this.Session().Now())
                                      .WithAssignedVatRegime(this.DerivedVatRegime)
                                      .WithAssignedIrpfRegime(this.DerivedIrpfRegime)
                                      .WithCustomerReference(this.CustomerReference)
                                      .WithPurchaseInvoiceType(new PurchaseInvoiceTypes(this.Session()).PurchaseInvoice)
                                      .Build();

                foreach (OrderAdjustment orderAdjustment in this.OrderAdjustments)
                {
                    OrderAdjustment newAdjustment = null;
                    if (orderAdjustment.GetType().Name.Equals(typeof(DiscountAdjustment).Name))
                    {
                        newAdjustment = new DiscountAdjustmentBuilder(this.Session()).Build();
                    }

                    if (orderAdjustment.GetType().Name.Equals(typeof(SurchargeAdjustment).Name))
                    {
                        newAdjustment = new SurchargeAdjustmentBuilder(this.Session()).Build();
                    }

                    if (orderAdjustment.GetType().Name.Equals(typeof(Fee).Name))
                    {
                        newAdjustment = new FeeBuilder(this.Session()).Build();
                    }

                    if (orderAdjustment.GetType().Name.Equals(typeof(ShippingAndHandlingCharge).Name))
                    {
                        newAdjustment = new ShippingAndHandlingChargeBuilder(this.Session()).Build();
                    }

                    if (orderAdjustment.GetType().Name.Equals(typeof(MiscellaneousCharge).Name))
                    {
                        newAdjustment = new MiscellaneousChargeBuilder(this.Session()).Build();
                    }

                    newAdjustment.Amount ??= orderAdjustment.Amount;
                    newAdjustment.Percentage ??= orderAdjustment.Percentage;
                    purchaseInvoice.AddOrderAdjustment(newAdjustment);
                }

                foreach (PurchaseOrderItem orderItem in this.ValidOrderItems)
                {
                    if (orderItem.CanInvoice)
                    {
                        var invoiceItem = new PurchaseInvoiceItemBuilder(this.Strategy.Session)
                                          .WithAssignedUnitPrice(orderItem.UnitPrice)
                                          .WithInvoiceItemType(orderItem.InvoiceItemType)
                                          .WithPart(orderItem.Part)
                                          .WithQuantity(orderItem.QuantityOrdered)
                                          .WithAssignedVatRegime(orderItem.AssignedVatRegime)
                                          .WithAssignedIrpfRegime(orderItem.AssignedIrpfRegime)
                                          .WithDescription(orderItem.Description)
                                          .WithInternalComment(orderItem.InternalComment)
                                          .WithMessage(orderItem.Message)
                                          .Build();

                        purchaseInvoice.AddPurchaseInvoiceItem(invoiceItem);

                        new OrderItemBillingBuilder(this.Strategy.Session)
                        .WithQuantity(orderItem.QuantityOrdered)
                        .WithAmount(orderItem.TotalBasePrice)
                        .WithOrderItem(orderItem)
                        .WithInvoiceItem(invoiceItem)
                        .Build();
                    }
                }
            }
        }