Ejemplo n.º 1
0
        public static SalesInvoiceBuilder WithSalesExternalB2CInvoiceDefaults(this SalesInvoiceBuilder @this, Organisation internalOrganisation)
        {
            var faker = @this.Session.Faker();

            var customer = internalOrganisation.ActiveCustomers.Where(v => v.GetType().Name == typeof(Person).Name).FirstOrDefault();

            var salesInvoiceItem_Default = new SalesInvoiceItemBuilder(@this.Session).WithDefaults().Build();
            var salesInvoiceItem_Product = new SalesInvoiceItemBuilder(@this.Session).WithProductItemDefaults().Build();
            var salesInvoiceItem_Part    = new SalesInvoiceItemBuilder(@this.Session).WithPartItemDefaults().Build();

            var salesInvoiceType = new SalesInvoiceTypes(@this.Session).SalesInvoice;
            var paymentMethod    = faker.Random.ListItem(@this.Session.Extent <PaymentMethod>());

            @this.WithCustomerReference(faker.Random.String(16).ToUpper(CultureInfo.CurrentCulture));
            @this.WithBilledFrom(internalOrganisation);
            @this.WithBilledFromContactPerson(internalOrganisation.CurrentContacts.FirstOrDefault());
            @this.WithDescription(faker.Lorem.Sentence());
            @this.WithComment(faker.Lorem.Sentence());
            @this.WithInternalComment(faker.Lorem.Sentence());
            @this.WithBillToCustomer(customer);
            @this.WithShipToCustomer(customer);
            @this.WithSalesInvoiceType(salesInvoiceType);
            @this.WithTotalListPrice(faker.Random.Decimal());
            @this.WithAssignedPaymentMethod(paymentMethod);
            @this.WithSalesInvoiceItem(salesInvoiceItem_Default);
            @this.WithSalesInvoiceItem(salesInvoiceItem_Product);
            @this.WithSalesInvoiceItem(salesInvoiceItem_Part);
            @this.WithAdvancePayment(faker.Random.Decimal());
            @this.WithSalesTerm(new InvoiceTermBuilder(@this.Session).WithDefaultsForPaymentNetDays().Build());
            @this.WithSalesTerm(new IncoTermBuilder(@this.Session).WithDefaults().Build());
            @this.WithSalesTerm(new InvoiceTermBuilder(@this.Session).WithDefaults().Build());
            @this.WithSalesTerm(new OrderTermBuilder(@this.Session).WithDefaults().Build());

            return(@this);
        }
        public static SalesInvoiceBuilder WithSalesInternalInvoiceDefaults(this SalesInvoiceBuilder @this, Organisation internalOrganisation)
        {
            var faker = @this.Session.Faker();

            var internalOrganisations = @this.Session.Extent <Organisation>();

            var otherInternalOrganization = internalOrganisations.Except(new List <Organisation> {
                internalOrganisation
            }).FirstOrDefault();

            var endCustomer = faker.Random.ListItem(internalOrganisation.ActiveCustomers);
            var salesInvoiceItem_Default = new SalesInvoiceItemBuilder(@this.Session).WithDefaults().Build();
            var salesInvoiceItem_Product = new SalesInvoiceItemBuilder(@this.Session).WithProductItemDefaults().Build();
            var salesInvoiceItem_Part    = new SalesInvoiceItemBuilder(@this.Session).WithPartItemDefaults().Build();

            var salesInvoiceType = new SalesInvoiceTypes(@this.Session).SalesInvoice;
            var paymentMethod    = faker.Random.ListItem(@this.Session.Extent <PaymentMethod>());

            @this.WithCustomerReference(faker.Random.String(16).ToUpper(CultureInfo.CurrentCulture));
            @this.WithBilledFrom(internalOrganisation);
            @this.WithBilledFromContactMechanism(internalOrganisation.CurrentPartyContactMechanisms.Select(v => v.ContactMechanism).FirstOrDefault());
            @this.WithBilledFromContactPerson(internalOrganisation.CurrentContacts.FirstOrDefault());
            @this.WithDescription(faker.Lorem.Sentence());
            @this.WithComment(faker.Lorem.Sentence());
            @this.WithInternalComment(faker.Lorem.Sentence());
            @this.WithBillToCustomer(otherInternalOrganization.CurrentContacts.FirstOrDefault());
            @this.WithBillToContactMechanism(otherInternalOrganization.CurrentPartyContactMechanisms.Select(v => v.ContactMechanism).FirstOrDefault());
            @this.WithBillToContactPerson(otherInternalOrganization.CurrentContacts.FirstOrDefault());
            @this.WithBillToEndCustomer(endCustomer);
            @this.WithBillToEndCustomerContactMechanism(endCustomer.CurrentPartyContactMechanisms.Select(v => v.ContactMechanism).FirstOrDefault());
            @this.WithBillToEndCustomerContactPerson(endCustomer.CurrentContacts.FirstOrDefault());
            @this.WithShipToEndCustomer(endCustomer);
            @this.WithShipToEndCustomerAddress(endCustomer.ShippingAddress);
            @this.WithShipToEndCustomerContactPerson(endCustomer.CurrentContacts.FirstOrDefault());
            @this.WithShipToCustomer(otherInternalOrganization);
            @this.WithShipToAddress(otherInternalOrganization.ShippingAddress);
            @this.WithShipToContactPerson(otherInternalOrganization.CurrentContacts.FirstOrDefault());
            @this.WithSalesInvoiceType(salesInvoiceType);
            @this.WithTotalListPrice(faker.Random.Decimal());
            @this.WithPaymentMethod(paymentMethod);
            @this.WithSalesInvoiceItem(salesInvoiceItem_Default);
            @this.WithSalesInvoiceItem(salesInvoiceItem_Product);
            @this.WithSalesInvoiceItem(salesInvoiceItem_Part);
            @this.WithAdvancePayment(faker.Random.Decimal());
            @this.WithPaymentDays(faker.Random.Int(7, 30));
            @this.WithIsRepeatingInvoice(faker.Random.Bool());
            @this.WithSalesTerm(new IncoTermBuilder(@this.Session).WithDefaults().Build());
            @this.WithSalesTerm(new InvoiceTermBuilder(@this.Session).WithDefaults().Build());
            @this.WithSalesTerm(new OrderTermBuilder(@this.Session).WithDefaults().Build());

            return(@this);
        }
Ejemplo n.º 3
0
        public void AppsCreateSalesInvoice(PurchaseInvoiceCreateSalesInvoice method)
        {
            var derivation = new Derivation(this.Strategy.Session);

            var salesInvoice = new SalesInvoiceBuilder(this.Strategy.Session)
                               .WithPurchaseInvoice(this)
                               .WithBilledFrom(this.BilledTo)
                               .WithBilledFromContactPerson(this.BilledToContactPerson)
                               .WithBillToCustomer(this.BillToEndCustomer)
                               .WithBillToContactMechanism(this.BillToEndCustomerContactMechanism)
                               .WithBillToContactPerson(this.BillToEndCustomerContactPerson)
                               .WithShipToCustomer(this.ShipToEndCustomer)
                               .WithShipToAddress(this.ShipToEndCustomerAddress)
                               .WithShipToContactPerson(this.ShipToEndCustomerContactPerson)
                               .WithDescription(this.Description)
                               .WithInvoiceDate(DateTime.UtcNow)
                               .WithSalesInvoiceType(new SalesInvoiceTypes(this.Strategy.Session).SalesInvoice)
                               .WithVatRegime(this.VatRegime)
                               .WithDiscountAdjustment(this.DiscountAdjustment)
                               .WithSurchargeAdjustment(this.SurchargeAdjustment)
                               .WithShippingAndHandlingCharge(this.ShippingAndHandlingCharge)
                               .WithFee(this.Fee)
                               .WithCustomerReference(this.CustomerReference)
                               .WithPaymentMethod(this.BillToCustomerPaymentMethod)
                               .WithComment(this.Comment)
                               .WithInternalComment(this.InternalComment)
                               .Build();

            foreach (PurchaseInvoiceItem purchaseInvoiceItem in this.PurchaseInvoiceItems)
            {
                var invoiceItem = new SalesInvoiceItemBuilder(this.Strategy.Session)
                                  .WithInvoiceItemType(purchaseInvoiceItem.InvoiceItemType)
                                  .WithActualUnitPrice(purchaseInvoiceItem.ActualUnitPrice)
                                  .WithProduct(purchaseInvoiceItem.Product)
                                  .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();
            }
        }
Ejemplo n.º 4
0
        private static void CreateInvoiceItems(this WorkEffort @this, SalesInvoice salesInvoice)
        {
            var session = @this.Strategy.Session;

            var timeEntriesByBillingRate = @this.ServiceEntriesWhereWorkEffort.OfType <TimeEntry>()
                                           .Where(v => (v.IsBillable && !v.BillableAmountOfTime.HasValue && v.AmountOfTime.HasValue) || v.BillableAmountOfTime.HasValue)
                                           .GroupBy(v => v.BillingRate)
                                           .Select(v => v)
                                           .ToArray();

            foreach (var rateGroup in timeEntriesByBillingRate)
            {
                var timeEntries = rateGroup.ToArray();

                var invoiceItem = new SalesInvoiceItemBuilder(session)
                                  .WithInvoiceItemType(new InvoiceItemTypes(session).Time)
                                  .WithAssignedUnitPrice(rateGroup.Key)
                                  .WithQuantity(timeEntries.Sum(v => v.BillableAmountOfTime ?? v.AmountOfTime ?? 0.0m))
                                  .Build();

                salesInvoice.AddSalesInvoiceItem(invoiceItem);

                foreach (var billableEntry in timeEntries)
                {
                    new TimeEntryBillingBuilder(session)
                    .WithTimeEntry(billableEntry)
                    .WithInvoiceItem(invoiceItem)
                    .Build();
                }
            }

            foreach (WorkEffortInventoryAssignment workEffortInventoryAssignment in @this.WorkEffortInventoryAssignmentsWhereAssignment)
            {
                var part = workEffortInventoryAssignment.InventoryItem.Part;

                var invoiceItem = new SalesInvoiceItemBuilder(session)
                                  .WithInvoiceItemType(new InvoiceItemTypes(session).PartItem)
                                  .WithPart(part)
                                  .WithAssignedUnitPrice(workEffortInventoryAssignment.UnitSellingPrice)
                                  .WithQuantity(workEffortInventoryAssignment.DerivedBillableQuantity)
                                  .WithCostOfGoodsSold(workEffortInventoryAssignment.CostOfGoodsSold)
                                  .Build();

                salesInvoice.AddSalesInvoiceItem(invoiceItem);

                new WorkEffortBillingBuilder(session)
                .WithWorkEffort(@this)
                .WithInvoiceItem(invoiceItem)
                .Build();
            }
        }
Ejemplo n.º 5
0
        public void GivenReceipt_WhenApplied_ThenInvoiceItemAmountPaidIsUpdated()
        {
            this.InstantiateObjects(this.Session);

            var productItem      = new InvoiceItemTypes(this.Session).ProductItem;
            var contactMechanism = new ContactMechanisms(this.Session).Extent().First;

            var invoice = new SalesInvoiceBuilder(this.Session)
                          .WithBillToCustomer(this.billToCustomer)
                          .WithAssignedBillToContactMechanism(contactMechanism)
                          .Build();

            var item1 = new SalesInvoiceItemBuilder(this.Session).WithProduct(this.good).WithQuantity(1).WithAssignedUnitPrice(100M).WithInvoiceItemType(productItem).Build();
            var item2 = new SalesInvoiceItemBuilder(this.Session).WithProduct(this.good).WithQuantity(1).WithAssignedUnitPrice(200M).WithInvoiceItemType(productItem).Build();
            var item3 = new SalesInvoiceItemBuilder(this.Session).WithProduct(this.good).WithQuantity(1).WithAssignedUnitPrice(300M).WithInvoiceItemType(productItem).Build();

            invoice.AddSalesInvoiceItem(item1);
            invoice.AddSalesInvoiceItem(item2);
            invoice.AddSalesInvoiceItem(item3);

            this.Session.Derive();

            new ReceiptBuilder(this.Session)
            .WithAmount(50)
            .WithPaymentApplication(new PaymentApplicationBuilder(this.Session).WithInvoiceItem(item2).WithAmountApplied(50).Build())
            .WithEffectiveDate(this.Session.Now())
            .Build();

            this.Session.Derive();

            Assert.Equal(0, item1.AmountPaid);
            Assert.Equal(50, item2.AmountPaid);
            Assert.Equal(0, item3.AmountPaid);

            new ReceiptBuilder(this.Session)
            .WithAmount(350)
            .WithPaymentApplication(new PaymentApplicationBuilder(this.Session).WithInvoiceItem(item1).WithAmountApplied(100).Build())
            .WithPaymentApplication(new PaymentApplicationBuilder(this.Session).WithInvoiceItem(item2).WithAmountApplied(150).Build())
            .WithPaymentApplication(new PaymentApplicationBuilder(this.Session).WithInvoiceItem(item3).WithAmountApplied(100).Build())
            .WithEffectiveDate(this.Session.Now())
            .Build();

            this.Session.Derive();

            Assert.Equal(100, item1.AmountPaid);
            Assert.Equal(200, item2.AmountPaid);
            Assert.Equal(100, item3.AmountPaid);
        }
Ejemplo n.º 6
0
        public void GivenReceipt_WhenApplied_ThenInvoiceItemAmountPaidIsUpdated()
        {
            this.InstantiateObjects(this.DatabaseSession);

            var productItem = new SalesInvoiceItemTypes(this.DatabaseSession).ProductItem;
            var contactMechanism = new ContactMechanisms(this.DatabaseSession).Extent().First;

            var invoice = new SalesInvoiceBuilder(this.DatabaseSession)
                .WithBillToCustomer(this.billToCustomer)
                .WithBillToContactMechanism(contactMechanism)
                .Build();

            var item1 = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(this.good).WithQuantity(1).WithActualUnitPrice(100M).WithSalesInvoiceItemType(productItem).Build();
            var item2 = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(this.good).WithQuantity(1).WithActualUnitPrice(200M).WithSalesInvoiceItemType(productItem).Build();
            var item3 = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(this.good).WithQuantity(1).WithActualUnitPrice(300M).WithSalesInvoiceItemType(productItem).Build();

            invoice.AddSalesInvoiceItem(item1);
            invoice.AddSalesInvoiceItem(item2);
            invoice.AddSalesInvoiceItem(item3);

            this.DatabaseSession.Derive(true);

            new ReceiptBuilder(this.DatabaseSession)
                .WithAmount(50)
                .WithPaymentApplication(new PaymentApplicationBuilder(this.DatabaseSession).WithInvoiceItem(item2).WithAmountApplied(50).Build())
                .WithEffectiveDate(DateTime.UtcNow)
                .Build();

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(0, item1.AmountPaid);
            Assert.AreEqual(50, item2.AmountPaid);
            Assert.AreEqual(0, item3.AmountPaid);

            new ReceiptBuilder(this.DatabaseSession)
                .WithAmount(350)
                .WithPaymentApplication(new PaymentApplicationBuilder(this.DatabaseSession).WithInvoiceItem(item1).WithAmountApplied(100).Build())
                .WithPaymentApplication(new PaymentApplicationBuilder(this.DatabaseSession).WithInvoiceItem(item2).WithAmountApplied(150).Build())
                .WithPaymentApplication(new PaymentApplicationBuilder(this.DatabaseSession).WithInvoiceItem(item3).WithAmountApplied(100).Build())
                .WithEffectiveDate(DateTime.UtcNow)
                .Build();

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(100, item1.AmountPaid);
            Assert.AreEqual(200, item2.AmountPaid);
            Assert.AreEqual(100, item3.AmountPaid);
        }
Ejemplo n.º 7
0
        public static SalesInvoiceItemBuilder WithDefaults(this SalesInvoiceItemBuilder @this)
        {
            var faker            = @this.Session.Faker();
            var invoiceItemTypes = @this.Session.Extent <InvoiceItemType>().ToList();

            var otherInvoiceItemTypes = invoiceItemTypes.Except(
                invoiceItemTypes.Where(v => v.UniqueId.Equals(InvoiceItemTypes.ProductItemId) || v.UniqueId.Equals(InvoiceItemTypes.PartItemId)).ToList())
                                        .ToList();

            @this.WithDescription(faker.Lorem.Sentences(2));
            @this.WithComment(faker.Lorem.Sentence());
            @this.WithInternalComment(faker.Lorem.Sentence());
            @this.WithInvoiceItemType(faker.Random.ListItem(otherInvoiceItemTypes));
            @this.WithMessage(faker.Lorem.Sentence());
            @this.WithQuantity(1);
            @this.WithAssignedUnitPrice(faker.Random.UInt());

            return(@this);
        }
Ejemplo n.º 8
0
        public static SalesInvoiceItemBuilder WithPartItemDefaults(this SalesInvoiceItemBuilder @this)
        {
            var faker           = @this.Session.Faker();
            var invoiceItemType = @this.Session.Extent <InvoiceItemType>().Where(v => v.UniqueId.Equals(InvoiceItemTypes.ProductItemId)).FirstOrDefault();

            var unifiedGoodExtent = @this.Session.Extent <UnifiedGood>();

            unifiedGoodExtent.Filter.AddEquals(M.UnifiedGood.InventoryItemKind.RoleType, new InventoryItemKinds(@this.Session).Serialised);
            var serializedPart = unifiedGoodExtent.First();

            @this.WithDescription(faker.Lorem.Sentences(2));
            @this.WithComment(faker.Lorem.Sentence());
            @this.WithInternalComment(faker.Lorem.Sentence());
            @this.WithInvoiceItemType(invoiceItemType);
            @this.WithProduct(serializedPart);
            @this.WithSerialisedItem(serializedPart.SerialisedItems.First);
            @this.WithMessage(faker.Lorem.Sentence());
            @this.WithQuantity(1);
            @this.WithAssignedUnitPrice(faker.Random.UInt());

            return(@this);
        }
Ejemplo n.º 9
0
        private void AppsInvoiceThis(IDerivation derivation)
        {
            var salesInvoice = new SalesInvoiceBuilder(this.Strategy.Session)
                               .WithBilledFrom(this.TakenBy)
                               .WithBilledFromContactMechanism(this.TakenByContactMechanism)
                               .WithBilledFromContactPerson(this.TakenByContactPerson)
                               .WithBillToCustomer(this.BillToCustomer)
                               .WithBillToContactMechanism(this.BillToContactMechanism)
                               .WithBillToContactPerson(this.BillToContactPerson)
                               .WithBillToEndCustomer(this.BillToEndCustomer)
                               .WithBillToEndCustomerContactMechanism(this.BillToEndCustomerContactMechanism)
                               .WithBillToEndCustomerContactPerson(this.BillToEndCustomerContactPerson)
                               .WithShipToCustomer(this.ShipToCustomer)
                               .WithShipToAddress(this.ShipToAddress)
                               .WithShipToContactPerson(this.ShipToContactPerson)
                               .WithShipToEndCustomer(this.ShipToEndCustomer)
                               .WithShipToEndCustomerAddress(this.ShipToEndCustomerAddress)
                               .WithShipToEndCustomerContactPerson(this.ShipToEndCustomerContactPerson)
                               .WithDescription(this.Description)
                               .WithStore(this.Store)
                               .WithInvoiceDate(DateTime.UtcNow)
                               .WithSalesChannel(this.SalesChannel)
                               .WithSalesInvoiceType(new SalesInvoiceTypes(this.Strategy.Session).SalesInvoice)
                               .WithVatRegime(this.VatRegime)
                               .WithDiscountAdjustment(this.DiscountAdjustment)
                               .WithSurchargeAdjustment(this.SurchargeAdjustment)
                               .WithShippingAndHandlingCharge(this.ShippingAndHandlingCharge)
                               .WithFee(this.Fee)
                               .WithCustomerReference(this.CustomerReference)
                               .WithPaymentMethod(this.PaymentMethod)
                               .Build();

            foreach (SalesOrderItem orderItem in this.ValidOrderItems)
            {
                var amountAlreadyInvoiced = orderItem.OrderItemBillingsWhereOrderItem.Sum(v => v.Amount);

                var leftToInvoice = (orderItem.QuantityOrdered * orderItem.ActualUnitPrice) - amountAlreadyInvoiced;

                if (leftToInvoice > 0)
                {
                    var invoiceItem = new SalesInvoiceItemBuilder(this.Strategy.Session)
                                      .WithInvoiceItemType(orderItem.InvoiceItemType)
                                      .WithActualUnitPrice(orderItem.ActualUnitPrice)
                                      .WithProduct(orderItem.Product)
                                      .WithQuantity(orderItem.QuantityOrdered)
                                      .WithDetails(orderItem.Details)
                                      .WithDescription(orderItem.Description)
                                      .WithInternalComment(orderItem.InternalComment)
                                      .WithMessage(orderItem.Message)
                                      .Build();

                    salesInvoice.AddSalesInvoiceItem(invoiceItem);

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

            foreach (SalesTerm salesTerm in this.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());
                }
            }
        }
Ejemplo n.º 10
0
        public void GivenSalesInvoice_WhenDerived_ThenTotalExVatIsAddedToPartyPackageRevenueHistory()
        {
            var productItem = new SalesInvoiceItemTypes(this.DatabaseSession).ProductItem;
            var contactMechanism = new ContactMechanisms(this.DatabaseSession).Extent().First;

            var euro = new Currencies(this.DatabaseSession).FindBy(Currencies.Meta.IsoCode, "EUR");
            var vatRate21 = new VatRateBuilder(this.DatabaseSession).WithRate(21).Build();
            var package1 = new PackageBuilder(this.DatabaseSession).WithName("package1").Build();
            var cat1 = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("cat for good1").WithPackage(package1).Build();

            var good1 = new GoodBuilder(this.DatabaseSession)
                .WithSku("10101")
                .WithVatRate(vatRate21)
                .WithName("good1")
                .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .WithPrimaryProductCategory(cat1)
                .Build();

            var customer = new Organisations(this.DatabaseSession).FindBy(Organisations.Meta.Name, "customer");
            var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation");
            internalOrganisation.PreferredCurrency = euro;

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

            var date = DateTime.UtcNow.AddYears(-1).AddMonths(-1);
            decimal revenuePastTwelveMonths = 0;
            for (var i = 1; i <= 13; i++)
            {
                var invoice = new SalesInvoiceBuilder(this.DatabaseSession)
                    .WithInvoiceDate(date)
                    .WithBillToCustomer(customer)
                    .WithBillToContactMechanism(contactMechanism)
                    .WithSalesChannel(new SalesChannels(this.DatabaseSession).WebChannel)
                    .WithSalesInvoiceType(new SalesInvoiceTypes(this.DatabaseSession).SalesInvoice)
                    .Build();

                var item = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantity(1).WithActualUnitPrice(i * 10M).WithSalesInvoiceItemType(productItem).Build();
                invoice.AddSalesInvoiceItem(item);

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

                var history = customer.PartyPackageRevenueHistoriesWhereParty.First;

                //// first iteration is too old
                if (i > 1)
                {
                    revenuePastTwelveMonths += i * 10M;
                }

                ////date in first iteration is too old, no history yet.
                if (history != null)
                {
                    Assert.AreEqual(revenuePastTwelveMonths, history.Revenue);
                }

                date = date.AddMonths(1);
            }
        }
Ejemplo n.º 11
0
        public void GivenSalesInvoice_WhenWrittenOff_ThenRevenueIsUpdated()
        {
            var euro = new Currencies(this.DatabaseSession).FindBy(Currencies.Meta.IsoCode, "EUR");
            var vatRate21 = new VatRateBuilder(this.DatabaseSession).WithRate(21).Build();
            var contactMechanism = new PostalAddressBuilder(this.DatabaseSession)
                .WithAddress1("Haverwerf 15")
                .WithPostalBoundary(new PostalBoundaryBuilder(this.DatabaseSession)
                                        .WithLocality("Mechelen")
                                        .WithCountry(new Countries(this.DatabaseSession).FindBy(Countries.Meta.IsoCode, "BE"))
                                        .Build())

                .Build();

            var good = new GoodBuilder(this.DatabaseSession)
                .WithSku("10101")
                .WithVatRate(vatRate21)
                .WithName("good")
                .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .Build();

            var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation");
            internalOrganisation.PreferredCurrency = euro;

            var customer = new OrganisationBuilder(this.DatabaseSession).WithName("customer").Build();

            var invoice1 = new SalesInvoiceBuilder(this.DatabaseSession)
                .WithInvoiceDate(DateTimeFactory.CreateDate(2010, 01, 01))
                .WithInvoiceNumber("1")
                .WithBillToCustomer(customer)
                .WithBillToContactMechanism(contactMechanism)
                .WithSalesChannel(new SalesChannels(this.DatabaseSession).WebChannel)
                .WithSalesInvoiceType(new SalesInvoiceTypes(this.DatabaseSession).SalesInvoice)
                .Build();

            new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer).WithInternalOrganisation(Singleton.Instance(this.DatabaseSession).DefaultInternalOrganisation).Build();

            var item1 = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good).WithQuantity(3).WithActualUnitPrice(15).WithSalesInvoiceItemType(new SalesInvoiceItemTypes(this.DatabaseSession).ProductItem).Build();
            invoice1.AddSalesInvoiceItem(item1);

            this.DatabaseSession.Derive(true);

            invoice1.Send();

            this.DatabaseSession.Derive(true);

            var invoice2 = new SalesInvoiceBuilder(this.DatabaseSession)
                .WithInvoiceDate(DateTimeFactory.CreateDate(2010, 01, 01))
                .WithInvoiceNumber("2")
                .WithBillToCustomer(customer)
                .WithBillToContactMechanism(contactMechanism)
                .WithSalesChannel(new SalesChannels(this.DatabaseSession).WebChannel)
                .WithSalesInvoiceType(new SalesInvoiceTypes(this.DatabaseSession).SalesInvoice)
                .Build();

            var item2 = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good).WithQuantity(1).WithActualUnitPrice(15).WithSalesInvoiceItemType(new SalesInvoiceItemTypes(this.DatabaseSession).ProductItem).Build();
            invoice2.AddSalesInvoiceItem(item2);

            this.DatabaseSession.Derive(true);

            var internalOrganisationRevenue = internalOrganisation.InternalOrganisationRevenuesWhereInternalOrganisation[0];
            var storeRevenue = invoice1.Store.StoreRevenuesWhereStore[0];
            var salesChannelRevenue = invoice1.SalesChannel.SalesChannelRevenuesWhereSalesChannel[0];
            var productRevenue = good.ProductRevenuesWhereProduct[0];
            var partyRevenue = customer.PartyRevenuesWhereParty[0];
            var partypPrductRevenue = customer.PartyProductRevenuesWhereParty[0];

            Assert.AreEqual(60, internalOrganisationRevenue.Revenue);
            Assert.AreEqual(2010, internalOrganisationRevenue.Year);
            Assert.AreEqual(60, storeRevenue.Revenue);
            Assert.AreEqual(2010, storeRevenue.Year);
            Assert.AreEqual(60, salesChannelRevenue.Revenue);
            Assert.AreEqual(2010, salesChannelRevenue.Year);
            Assert.AreEqual(60, productRevenue.Revenue);
            Assert.AreEqual(2010, productRevenue.Year);
            Assert.AreEqual(60, partyRevenue.Revenue);
            Assert.AreEqual(2010, partyRevenue.Year);
            Assert.AreEqual(60, partypPrductRevenue.Revenue);
            Assert.AreEqual(2010, partypPrductRevenue.Year);

            invoice2.WriteOff();

            this.DatabaseSession.Derive(true);

            internalOrganisationRevenue = internalOrganisation.InternalOrganisationRevenuesWhereInternalOrganisation[0];
            storeRevenue = invoice1.Store.StoreRevenuesWhereStore[0];
            salesChannelRevenue = invoice1.SalesChannel.SalesChannelRevenuesWhereSalesChannel[0];
            productRevenue = good.ProductRevenuesWhereProduct[0];
            partyRevenue = customer.PartyRevenuesWhereParty[0];
            partypPrductRevenue = customer.PartyProductRevenuesWhereParty[0];

            Assert.AreEqual(45, internalOrganisationRevenue.Revenue);
            Assert.AreEqual(2010, internalOrganisationRevenue.Year);
            Assert.AreEqual(45, storeRevenue.Revenue);
            Assert.AreEqual(2010, storeRevenue.Year);
            Assert.AreEqual(45, salesChannelRevenue.Revenue);
            Assert.AreEqual(2010, salesChannelRevenue.Year);
            Assert.AreEqual(45, productRevenue.Revenue);
            Assert.AreEqual(2010, productRevenue.Year);
            Assert.AreEqual(45, partyRevenue.Revenue);
            Assert.AreEqual(2010, partyRevenue.Year);
            Assert.AreEqual(45, partypPrductRevenue.Revenue);
            Assert.AreEqual(2010, partypPrductRevenue.Year);
        }
Ejemplo n.º 12
0
        public void GivenInvoiceItemWithDiscountPercentageForPartyClassification_WhenDeriving_ThenUseDiscountComponentsForPartyClassification()
        {
            const decimal quantity = 3;
            const decimal percentage = 5;

            var classification = new IndustryClassificationBuilder(this.DatabaseSession).WithName("gold customer").Build();
            new DiscountComponentBuilder(this.DatabaseSession)
                .WithSpecifiedFor(this.internalOrganisation)
                .WithDescription("discount good for party classification")
                .WithPartyClassification(classification)
                .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.billToCustomer.AddPartyClassification(classification);

            this.invoice.ShipToCustomer = this.shipToCustomer;

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

            this.DatabaseSession.Derive(true);

            var amount = decimal.Round((this.currentGood1BasePrice.Price * percentage) / 100, 2);
            Assert.AreEqual(this.currentGood1BasePrice.Price, item1.UnitBasePrice);
            Assert.AreEqual(amount, item1.UnitDiscount);
            Assert.AreEqual(0, item1.UnitSurcharge);
            Assert.AreEqual(this.currentGood1BasePrice.Price - amount, 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.º 13
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.º 14
0
        public void GivenBillToCustomerWithDifferentCurrency_WhenDerivingPrices_ThenCalculatePricesInPreferredCurrency()
        {
            var poundSterling = new Currencies(this.DatabaseSession).FindBy(Currencies.Meta.IsoCode, "GBP");

            const decimal conversionfactor = 0.8553M;
            var euroToPoundStirling = new UnitOfMeasureConversionBuilder(this.DatabaseSession)
                .WithConversionFactor(conversionfactor)
                .WithToUnitOfMeasure(poundSterling)
                .WithStartDate(DateTime.UtcNow)
                .Build();

            var euro = new Currencies(this.DatabaseSession).FindBy(Currencies.Meta.IsoCode, "EUR");
            euro.AddUnitOfMeasureConversion(euroToPoundStirling);

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

            this.InstantiateObjects(this.DatabaseSession);

            Assert.AreEqual(euro, this.invoice.CustomerCurrency);

            this.billToCustomer.PreferredCurrency = poundSterling;

            var newInvoice = new SalesInvoiceBuilder(this.DatabaseSession)
                .WithBillToCustomer(this.billToCustomer)
                .WithBilledFromInternalOrganisation(this.internalOrganisation)
                .WithBillToContactMechanism(this.billToContactMechanismMechelen)
                .Build();

            const decimal quantity = 3;
            var item1 = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(this.good).WithSalesInvoiceItemType(new SalesInvoiceItemTypes(this.DatabaseSession).ProductItem).WithQuantity(quantity).Build();
            newInvoice.AddSalesInvoiceItem(item1);

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(poundSterling, newInvoice.CustomerCurrency);

            Assert.AreEqual(decimal.Round(item1.TotalBasePrice * conversionfactor, 2), item1.TotalBasePriceCustomerCurrency);
            Assert.AreEqual(0, item1.TotalDiscount);
            Assert.AreEqual(0, item1.TotalSurcharge);
            Assert.AreEqual(decimal.Round(item1.TotalExVat * conversionfactor, 2), item1.TotalExVatCustomerCurrency);
        }
Ejemplo n.º 15
0
        public void GivenProductWithMultipleBasePrices_WhenDeriving_ThenLowestUnitPriceMustBeCalculated()
        {
            this.InstantiateObjects(this.DatabaseSession);

            this.invoice.ShipToAddress = this.billToContactMechanismMechelen;

            var item1 = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(this.good).WithSalesInvoiceItemType(new SalesInvoiceItemTypes(this.DatabaseSession).ProductItem).WithQuantity(3).Build();
            this.invoice.AddSalesInvoiceItem(item1);

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(this.currentBasePriceGeoBoundary.Price, item1.CalculatedUnitPrice);

            var invoice2 = new SalesInvoiceBuilder(this.DatabaseSession)
                .WithBilledFromInternalOrganisation(this.internalOrganisation)
                .WithBillToCustomer(this.billToCustomer)
                .WithBillToContactMechanism(this.billToContactMechanismMechelen)
                .Build();

            item1 = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(this.good).WithSalesInvoiceItemType(new SalesInvoiceItemTypes(this.DatabaseSession).ProductItem).WithQuantity(3).Build();
            invoice2.AddSalesInvoiceItem(item1);

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(this.currentGood1BasePrice.Price, item1.CalculatedUnitPrice);
        }
Ejemplo n.º 16
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.º 17
0
        public void GivenSalesInvoice_WhenDeriving_ThenTotalAmountMustBeDerived()
        {
            var euro = new Currencies(this.DatabaseSession).FindBy(Currencies.Meta.IsoCode, "EUR");
            var supplier = new OrganisationBuilder(this.DatabaseSession).WithName("supplier").Build();
            var vatRate21 = new VatRateBuilder(this.DatabaseSession).WithRate(19).Build();

            var good = new GoodBuilder(this.DatabaseSession)
                .WithSku("10101")
                .WithVatRate(vatRate21)
                .WithName("good")
                .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .Build();

            var goodPurchasePrice = new ProductPurchasePriceBuilder(this.DatabaseSession)
                .WithCurrency(euro)
                .WithFromDate(DateTime.UtcNow)
                .WithPrice(7)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .Build();

            new SupplierOfferingBuilder(this.DatabaseSession)
                .WithProduct(good)
                .WithSupplier(supplier)
                .WithFromDate(DateTime.UtcNow)
                .WithProductPurchasePrice(goodPurchasePrice)
                .Build();

            var productItem = new SalesInvoiceItemTypes(this.DatabaseSession).ProductItem;

            var customer = new OrganisationBuilder(this.DatabaseSession).WithName("customer").Build();
            var contactMechanism = new PostalAddressBuilder(this.DatabaseSession)
                .WithAddress1("Haverwerf 15")
                .WithPostalBoundary(new PostalBoundaryBuilder(this.DatabaseSession)
                                        .WithLocality("Mechelen")
                                        .WithCountry(new Countries(this.DatabaseSession).FindBy(Countries.Meta.IsoCode, "BE"))
                                        .Build())

                .Build();

            new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer).WithInternalOrganisation(Singleton.Instance(this.DatabaseSession).DefaultInternalOrganisation).Build();

            this.DatabaseSession.Derive(true);

            var invoice = new SalesInvoiceBuilder(this.DatabaseSession).WithBillToCustomer(customer).WithBillToContactMechanism(contactMechanism).Build();

            var item1 = new SalesInvoiceItemBuilder(this.DatabaseSession)
                .WithProduct(good)
                .WithSalesInvoiceItemType(productItem)
                .WithQuantity(1)
                .WithActualUnitPrice(8)
                .Build();

            invoice.AddSalesInvoiceItem(item1);

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(8, invoice.TotalExVat);
            Assert.AreEqual(1.52M, invoice.TotalVat);
            Assert.AreEqual(9.52M, invoice.TotalIncVat);

            var item2 = new SalesInvoiceItemBuilder(this.DatabaseSession)
                .WithProduct(good)
                .WithSalesInvoiceItemType(productItem)
                .WithQuantity(1)
                .WithActualUnitPrice(8)
                .Build();

            var item3 = new SalesInvoiceItemBuilder(this.DatabaseSession)
                .WithProduct(good)
                .WithSalesInvoiceItemType(productItem)
                .WithQuantity(1)
                .WithActualUnitPrice(8)
                .Build();

            invoice.AddSalesInvoiceItem(item2);
            invoice.AddSalesInvoiceItem(item3);

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(24, invoice.TotalExVat);
            Assert.AreEqual(4.56M, invoice.TotalVat);
            Assert.AreEqual(28.56M, invoice.TotalIncVat);
            Assert.AreEqual(21, invoice.TotalPurchasePrice);
            Assert.AreEqual(invoice.TotalListPrice, invoice.TotalExVat);
        }
Ejemplo n.º 18
0
        public static void Full(this Singleton @this, DirectoryInfo dataPath, Faker faker)
        {
            var dutchLocale = new Locales(@this.Session()).DutchNetherlands;

            @this.AddAdditionalLocale(dutchLocale);

            var administrator = new PersonBuilder(@this.Session()).WithUserName("administrator").Build();

            new UserGroups(@this.Session()).Administrators.AddMember(administrator);
            new UserGroups(@this.Session()).Creators.AddMember(administrator);

            @this.Session().Derive();

            var euro = new Currencies(@this.Session()).FindBy(M.Currency.IsoCode, "EUR");

            var be = new Countries(@this.Session()).FindBy(M.Country.IsoCode, "BE");
            var us = new Countries(@this.Session()).FindBy(M.Country.IsoCode, "US");

            var allorsLogo = dataPath + @"\www\admin\images\logo.png";

            var allors = Organisations.CreateInternalOrganisation(
                session: @this.Session(),
                name: "Allors BVBA",
                address: "Kleine Nieuwedijkstraat 4",
                postalCode: "2800",
                locality: "Mechelen",
                country: be,
                phone1CountryCode: "+32",
                phone1: "2 335 2335",
                phone1Purpose: new ContactMechanismPurposes(@this.Session()).GeneralPhoneNumber,
                phone2CountryCode: string.Empty,
                phone2: string.Empty,
                phone2Purpose: null,
                emailAddress: "*****@*****.**",
                websiteAddress: "www.allors.com",
                taxNumber: "BE 0476967014",
                bankName: "ING",
                facilityName: "Allors Warehouse 1",
                bic: "BBRUBEBB",
                iban: "BE89 3200 1467 7685",
                currency: euro,
                logo: allorsLogo,
                storeName: "Allors Store",
                billingProcess: new BillingProcesses(@this.Session()).BillingForOrderItems,
                outgoingShipmentNumberPrefix: "a-CS",
                salesInvoiceNumberPrefix: "a-SI",
                salesOrderNumberPrefix: "a-SO",
                purchaseOrderNumberPrefix: "a-PO",
                purchaseInvoiceNumberPrefix: "a-PI",
                requestNumberPrefix: "a-RFQ",
                quoteNumberPrefix: "a-Q",
                productNumberPrefix: "A-",
                workEffortPrefix: "a-WO-",
                creditNoteNumberPrefix: "a-CN-",
                isImmediatelyPicked: true,
                autoGenerateShipmentPackage: true,
                isImmediatelyPacked: true,
                isAutomaticallyShipped: true,
                autoGenerateCustomerShipment: true,
                isAutomaticallyReceived: false,
                autoGeneratePurchaseShipment: false,
                useCreditNoteSequence: true,
                requestCounterValue: 1,
                quoteCounterValue: 1,
                orderCounterValue: 1,
                purchaseOrderCounterValue: 1,
                invoiceCounterValue: 1,
                purchaseInvoiceCounterValue: 1,
                purchaseOrderNeedsApproval: true,
                purchaseOrderApprovalThresholdLevel1: 1000M,
                purchaseOrderApprovalThresholdLevel2: 5000M,
                serialisedItemSoldOn: new SerialisedItemSoldOns(@this.Session()).CustomerShipmentShip,
                collectiveWorkEffortInvoice: true);

            var dipu = Organisations.CreateInternalOrganisation(
                session: @this.Session(),
                name: "Dipu BVBA",
                address: "Kleine Nieuwedijkstraat 2",
                postalCode: "2800",
                locality: "Mechelen",
                country: be,
                phone1CountryCode: "+32",
                phone1: "2 15 49 49 49",
                phone1Purpose: new ContactMechanismPurposes(@this.Session()).GeneralPhoneNumber,
                phone2CountryCode: string.Empty,
                phone2: string.Empty,
                phone2Purpose: null,
                emailAddress: "*****@*****.**",
                websiteAddress: "www.dipu.com",
                taxNumber: "BE 0445366489",
                bankName: "ING",
                facilityName: "Dipu Facility",
                bic: "BBRUBEBB",
                iban: "BE23 3300 6167 6391",
                currency: euro,
                logo: allorsLogo,
                storeName: "Dipu Store",
                billingProcess: new BillingProcesses(@this.Session()).BillingForOrderItems,
                outgoingShipmentNumberPrefix: "d-CS",
                salesInvoiceNumberPrefix: "d-SI",
                salesOrderNumberPrefix: "d-SO",
                purchaseOrderNumberPrefix: "d-PO",
                purchaseInvoiceNumberPrefix: "d-PI",
                requestNumberPrefix: "d-RFQ",
                quoteNumberPrefix: "d-Q",
                productNumberPrefix: "D-",
                workEffortPrefix: "a-WO-",
                creditNoteNumberPrefix: "d-CN-",
                isImmediatelyPicked: true,
                autoGenerateShipmentPackage: true,
                isImmediatelyPacked: true,
                isAutomaticallyShipped: true,
                autoGenerateCustomerShipment: true,
                isAutomaticallyReceived: false,
                autoGeneratePurchaseShipment: false,
                useCreditNoteSequence: true,
                requestCounterValue: 1,
                quoteCounterValue: 1,
                orderCounterValue: 1,
                purchaseOrderCounterValue: 1,
                purchaseInvoiceCounterValue: 1,
                invoiceCounterValue: 1,
                purchaseOrderNeedsApproval: false,
                purchaseOrderApprovalThresholdLevel1: null,
                purchaseOrderApprovalThresholdLevel2: null,
                serialisedItemSoldOn: new SerialisedItemSoldOns(@this.Session()).CustomerShipmentShip,
                collectiveWorkEffortInvoice: true);

            // Give Administrator access
            new EmploymentBuilder(@this.Session()).WithEmployee(administrator).WithEmployer(allors).Build();

            @this.Settings.DefaultFacility = allors.FacilitiesWhereOwner.First;

            var allorsEmployee1                   = allors.CreateEmployee("letmein", faker);
            var allorsEmployee2                   = allors.CreateEmployee("letmein", faker);
            var allorsProductQuoteApprover        = allors.CreateEmployee("letmein", faker);
            var allorsPurchaseInvoiceApprover     = allors.CreateEmployee("letmein", faker);
            var allorsPurchaseOrderApproverLevel1 = allors.CreateEmployee("letmein", faker);
            var allorsPurchaseOrderApproverLevel2 = allors.CreateEmployee("letmein", faker);

            var dipuEmployee                = dipu.CreateEmployee("letmein", faker);
            var dipuProductQuoteApprover    = dipu.CreateEmployee("letmein", faker);
            var dipuPurchaseInvoiceApprover = dipu.CreateEmployee("letmein", faker);

            new FacilityBuilder(@this.Session())
            .WithName("Allors warehouse 2")
            .WithFacilityType(new FacilityTypes(@this.Session()).Warehouse)
            .WithOwner(allors)
            .Build();

            var vatRate      = new VatRateBuilder(@this.Session()).WithRate(21).Build();
            var manufacturer = new OrganisationBuilder(@this.Session()).WithManufacturerDefaults(faker).Build();

            allors.CreateSupplier(faker);
            allors.CreateSupplier(faker);

            allors.CreateSubContractor(faker);
            allors.CreateSubContractor(faker);

            @this.Session().Derive();

            var nonSerialisedPart1 = allors.CreateNonSerialisedNonUnifiedPart(faker);
            var nonSerialisedPart2 = allors.CreateNonSerialisedNonUnifiedPart(faker);
            var serialisedPart1    = allors.CreateSerialisedNonUnifiedPart(faker);
            var serialisedPart2    = allors.CreateSerialisedNonUnifiedPart(faker);

            var good1 = new NonUnifiedGoodBuilder(@this.Session()).WithNonSerialisedPartDefaults(allors).Build();

            var good2 = new NonUnifiedGoodBuilder(@this.Session()).WithSerialisedPartDefaults(allors).Build();

            var serialisedItem = new SerialisedItemBuilder(@this.Session()).WithDefaults(allors).Build();

            serialisedPart1.AddSerialisedItem(serialisedItem);

            new InventoryItemTransactionBuilder(@this.Session())
            .WithSerialisedItem(serialisedItem)
            .WithFacility(allors.FacilitiesWhereOwner.First)
            .WithQuantity(1)
            .WithReason(new InventoryTransactionReasons(@this.Session()).IncomingShipment)
            .WithSerialisedInventoryItemState(new SerialisedInventoryItemStates(@this.Session()).Good)
            .Build();

            var good3 = new NonUnifiedGoodBuilder(@this.Session()).WithNonSerialisedPartDefaults(allors).Build();

            var good4 = new NonUnifiedGoodBuilder(@this.Session()).WithSerialisedPartDefaults(allors).Build();

            var productCategory1 = new ProductCategoryBuilder(@this.Session())
                                   .WithInternalOrganisation(allors)
                                   .WithName("Best selling gizmo's")
                                   .WithLocalisedName(new LocalisedTextBuilder(@this.Session()).WithText("Meest verkochte gizmo's").WithLocale(dutchLocale).Build())
                                   .Build();

            var productCategory2 = new ProductCategoryBuilder(@this.Session())
                                   .WithInternalOrganisation(allors)
                                   .WithName("Big Gizmo's")
                                   .WithLocalisedName(new LocalisedTextBuilder(@this.Session()).WithText("Grote Gizmo's").WithLocale(dutchLocale).Build())
                                   .Build();

            var productCategory3 = new ProductCategoryBuilder(@this.Session())
                                   .WithInternalOrganisation(allors)
                                   .WithName("Small gizmo's")
                                   .WithLocalisedName(new LocalisedTextBuilder(@this.Session()).WithText("Kleine gizmo's").WithLocale(dutchLocale).Build())
                                   .WithProduct(good1)
                                   .WithProduct(good2)
                                   .WithProduct(good3)
                                   .WithProduct(good4)
                                   .Build();

            new CatalogueBuilder(@this.Session())
            .WithInternalOrganisation(allors)
            .WithName("New gizmo's")
            .WithLocalisedName(new LocalisedTextBuilder(@this.Session()).WithText("Nieuwe gizmo's").WithLocale(dutchLocale).Build())
            .WithDescription("Latest in the world of Gizmo's")
            .WithLocalisedDescription(new LocalisedTextBuilder(@this.Session()).WithText("Laatste in de wereld van Gizmo's").WithLocale(dutchLocale).Build())
            .WithProductCategory(productCategory1)
            .Build();

            @this.Session().Derive();

            var email2 = new EmailAddressBuilder(@this.Session())
                         .WithElectronicAddressString("*****@*****.**")
                         .Build();

            for (var i = 0; i < 10; i++)
            {
                var b2BCustomer = allors.CreateB2BCustomer(faker);

                @this.Session().Derive();

                new FaceToFaceCommunicationBuilder(@this.Session())
                .WithDescription($"Meeting {i}")
                .WithSubject($"meeting {i}")
                .WithEventPurpose(new CommunicationEventPurposes(@this.Session()).Meeting)
                .WithFromParty(allors.CurrentContacts.First)
                .WithToParty(b2BCustomer.CurrentContacts.First)
                .WithOwner(administrator)
                .WithActualStart(@this.Session().Now())
                .Build();

                new EmailCommunicationBuilder(@this.Session())
                .WithDescription($"Email {i}")
                .WithSubject($"email {i}")
                .WithFromParty(allors.CurrentContacts.First)
                .WithToParty(b2BCustomer.CurrentContacts.First)
                .WithFromEmail(allors.GeneralEmail)
                .WithToEmail(email2)
                .WithEventPurpose(new CommunicationEventPurposes(@this.Session()).Meeting)
                .WithOwner(administrator)
                .WithActualStart(@this.Session().Now())
                .Build();

                new LetterCorrespondenceBuilder(@this.Session())
                .WithDescription($"Letter {i}")
                .WithSubject($"letter {i}")
                .WithFromParty(administrator)
                .WithToParty(b2BCustomer.CurrentContacts.First)
                .WithEventPurpose(new CommunicationEventPurposes(@this.Session()).Meeting)
                .WithOwner(administrator)
                .WithActualStart(@this.Session().Now())
                .Build();

                new PhoneCommunicationBuilder(@this.Session())
                .WithDescription($"Phone {i}")
                .WithSubject($"phone {i}")
                .WithFromParty(administrator)
                .WithToParty(b2BCustomer.CurrentContacts.First)
                .WithEventPurpose(new CommunicationEventPurposes(@this.Session()).Meeting)
                .WithOwner(administrator)
                .WithActualStart(@this.Session().Now())
                .Build();

                var requestForQuote = new RequestForQuoteBuilder(@this.Session())
                                      .WithEmailAddress($"customer{i}@acme.com")
                                      .WithTelephoneNumber("+1 234 56789")
                                      .WithRecipient(allors)
                                      .Build();

                var requestItem = new RequestItemBuilder(@this.Session())
                                  .WithSerialisedItem(serialisedItem)
                                  .WithProduct(serialisedItem.PartWhereSerialisedItem.NonUnifiedGoodsWherePart.FirstOrDefault())
                                  .WithComment($"Comment {i}")
                                  .WithQuantity(1)
                                  .Build();

                requestForQuote.AddRequestItem(requestItem);

                var quote = new ProductQuoteBuilder(@this.Session()).WithSerializedDefaults(allors).Build();

                var salesOrderItem1 = new SalesOrderItemBuilder(@this.Session())
                                      .WithDescription("first item")
                                      .WithProduct(good1)
                                      .WithAssignedUnitPrice(3000)
                                      .WithQuantityOrdered(1)
                                      .WithMessage(@"line1
line2")
                                      .WithInvoiceItemType(new InvoiceItemTypes(@this.Session()).ProductItem)
                                      .Build();

                var salesOrderItem2 = new SalesOrderItemBuilder(@this.Session())
                                      .WithDescription("second item")
                                      .WithAssignedUnitPrice(2000)
                                      .WithQuantityOrdered(2)
                                      .WithInvoiceItemType(new InvoiceItemTypes(@this.Session()).ProductItem)
                                      .Build();

                var salesOrderItem3 = new SalesOrderItemBuilder(@this.Session())
                                      .WithDescription("Fee")
                                      .WithAssignedUnitPrice(100)
                                      .WithQuantityOrdered(1)
                                      .WithInvoiceItemType(new InvoiceItemTypes(@this.Session()).Fee)
                                      .Build();

                var order = new SalesOrderBuilder(@this.Session())
                            .WithTakenBy(allors)
                            .WithBillToCustomer(b2BCustomer)
                            .WithBillToEndCustomerContactMechanism(b2BCustomer.BillingAddress)
                            .WithSalesOrderItem(salesOrderItem1)
                            .WithSalesOrderItem(salesOrderItem2)
                            .WithSalesOrderItem(salesOrderItem3)
                            .WithCustomerReference("a reference number")
                            .WithDescription("Sale of 1 used Aircraft Towbar")
                            .WithVatRegime(new VatRegimes(@this.Session()).Assessable)
                            .Build();

                var salesInvoiceItem1 = new SalesInvoiceItemBuilder(@this.Session())
                                        .WithDescription("first item")
                                        .WithProduct(good1)
                                        .WithAssignedUnitPrice(3000)
                                        .WithQuantity(1)
                                        .WithMessage(@"line1
line2")
                                        .WithInvoiceItemType(new InvoiceItemTypes(@this.Session()).ProductItem)
                                        .Build();

                var salesInvoiceItem2 = new SalesInvoiceItemBuilder(@this.Session())
                                        .WithDescription("second item")
                                        .WithAssignedUnitPrice(2000)
                                        .WithQuantity(2)
                                        .WithInvoiceItemType(new InvoiceItemTypes(@this.Session()).ProductItem)
                                        .Build();

                var salesInvoiceItem3 = new SalesInvoiceItemBuilder(@this.Session())
                                        .WithDescription("Fee")
                                        .WithAssignedUnitPrice(100)
                                        .WithQuantity(1)
                                        .WithInvoiceItemType(new InvoiceItemTypes(@this.Session()).Fee)
                                        .Build();

                var exw      = new IncoTermTypes(@this.Session()).Exw;
                var incoTerm = new IncoTermBuilder(@this.Session()).WithTermType(exw).WithTermValue("XW").Build();

                var salesInvoice = new SalesInvoiceBuilder(@this.Session())
                                   .WithBilledFrom(allors)
                                   .WithBillToCustomer(b2BCustomer)
                                   .WithBillToContactPerson(b2BCustomer.CurrentContacts.First)
                                   .WithBillToContactMechanism(b2BCustomer.BillingAddress)
                                   .WithSalesInvoiceItem(salesInvoiceItem1)
                                   .WithSalesInvoiceItem(salesInvoiceItem2)
                                   .WithSalesInvoiceItem(salesInvoiceItem3)
                                   .WithCustomerReference("a reference number")
                                   .WithDescription("Sale of 1 used Aircraft Towbar")
                                   .WithSalesInvoiceType(new SalesInvoiceTypes(@this.Session()).SalesInvoice)
                                   .WithSalesTerm(incoTerm)
                                   .WithVatRegime(new VatRegimes(@this.Session()).Assessable)
                                   .Build();

                for (var j = 0; j < 3; j++)
                {
                    var salesInvoiceItem = new SalesInvoiceItemBuilder(@this.Session())
                                           .WithDescription("Extra Charge")
                                           .WithAssignedUnitPrice(100 + j)
                                           .WithQuantity(j)
                                           .WithInvoiceItemType(new InvoiceItemTypes(@this.Session()).MiscCharge)
                                           .Build();

                    salesInvoice.AddSalesInvoiceItem(salesInvoiceItem);
                }
            }

            @this.Session().Derive();

            for (var i = 0; i < 4; i++)
            {
                var supplier = faker.Random.ListItem(allors.CurrentSuppliers);

                var purchaseInvoiceItem1 = new PurchaseInvoiceItemBuilder(@this.Session())
                                           .WithDescription("first item")
                                           .WithPart(nonSerialisedPart1)
                                           .WithAssignedUnitPrice(3000)
                                           .WithQuantity(1)
                                           .WithMessage(@"line1
line2")
                                           .WithInvoiceItemType(new InvoiceItemTypes(@this.Session()).PartItem)
                                           .Build();

                var purchaseInvoiceItem2 = new PurchaseInvoiceItemBuilder(@this.Session())
                                           .WithDescription("second item")
                                           .WithAssignedUnitPrice(2000)
                                           .WithQuantity(2)
                                           .WithPart(nonSerialisedPart2)
                                           .WithInvoiceItemType(new InvoiceItemTypes(@this.Session()).PartItem)
                                           .Build();

                var purchaseInvoiceItem3 = new PurchaseInvoiceItemBuilder(@this.Session())
                                           .WithDescription("Fee")
                                           .WithAssignedUnitPrice(100)
                                           .WithQuantity(1)
                                           .WithInvoiceItemType(new InvoiceItemTypes(@this.Session()).Fee)
                                           .Build();

                var purchaseInvoice = new PurchaseInvoiceBuilder(@this.Session())
                                      .WithBilledTo(allors)
                                      .WithBilledFrom(supplier)
                                      .WithPurchaseInvoiceItem(purchaseInvoiceItem1)
                                      .WithPurchaseInvoiceItem(purchaseInvoiceItem2)
                                      .WithPurchaseInvoiceItem(purchaseInvoiceItem3)
                                      .WithCustomerReference("a reference number")
                                      .WithDescription("Purchase of 1 used Aircraft Towbar")
                                      .WithPurchaseInvoiceType(new PurchaseInvoiceTypes(@this.Session()).PurchaseInvoice)
                                      .WithVatRegime(new VatRegimes(@this.Session()).Assessable)
                                      .Build();

                var purchaseOrderItem1 = new PurchaseOrderItemBuilder(@this.Session())
                                         .WithDescription("first purchase order item")
                                         .WithPart(nonSerialisedPart1)
                                         .WithQuantityOrdered(1)
                                         .Build();

                var purchaseOrder = new PurchaseOrderBuilder(@this.Session())
                                    .WithOrderedBy(allors)
                                    .WithTakenViaSupplier(supplier)
                                    .WithPurchaseOrderItem(purchaseOrderItem1)
                                    .WithCustomerReference("reference " + i)
                                    .Build();
            }

            var anOrganisation = new Organisations(@this.Session()).FindBy(M.Organisation.IsInternalOrganisation, false);

            var item = new SerialisedItemBuilder(@this.Session())
                       .WithSerialNumber("112")
                       .WithSerialisedItemAvailability(new SerialisedItemAvailabilities(@this.Session()).Sold)
                       .WithAvailableForSale(false)
                       .WithOwnedBy(anOrganisation)
                       .Build();

            nonSerialisedPart2.AddSerialisedItem(item);

            var workTask = new WorkTaskBuilder(@this.Session())
                           .WithTakenBy(allors)
                           .WithCustomer(anOrganisation)
                           .WithName("maintenance")
                           .Build();

            new WorkEffortFixedAssetAssignmentBuilder(@this.Session())
            .WithFixedAsset(item)
            .WithAssignment(workTask)
            .Build();

            var workOrderPart1 = allors.CreateNonSerialisedNonUnifiedPart(faker);
            var workOrderPart2 = allors.CreateNonSerialisedNonUnifiedPart(faker);
            var workOrderPart3 = allors.CreateNonSerialisedNonUnifiedPart(faker);

            @this.Session().Derive();

            var workOrder = new WorkTaskBuilder(@this.Session())
                            .WithName("Task")
                            .WithTakenBy(allors)
                            .WithFacility(new Facilities(@this.Session()).Extent().First)
                            .WithCustomer(anOrganisation)
                            .WithWorkEffortPurpose(new WorkEffortPurposes(@this.Session()).Maintenance)
                            .WithSpecialTerms("Net 45 Days")
                            .Build();

            new WorkEffortFixedAssetAssignmentBuilder(@this.Session())
            .WithFixedAsset(item)
            .WithAssignment(workOrder)
            .WithComment("Busted tailpipe")
            .Build();

            workOrder.CreateInventoryAssignment(workOrderPart1, 11);
            workOrder.CreateInventoryAssignment(workOrderPart2, 12);
            workOrder.CreateInventoryAssignment(workOrderPart3, 13);

            //// Work Effort Time Entries
            var yesterday      = DateTimeFactory.CreateDateTime(@this.Session().Now().AddDays(-1));
            var laterYesterday = DateTimeFactory.CreateDateTime(yesterday.AddHours(3));

            var today      = DateTimeFactory.CreateDateTime(@this.Session().Now());
            var laterToday = DateTimeFactory.CreateDateTime(today.AddHours(4));

            var tomorrow      = DateTimeFactory.CreateDateTime(@this.Session().Now().AddDays(1));
            var laterTomorrow = DateTimeFactory.CreateDateTime(tomorrow.AddHours(6));

            var standardRate = new RateTypes(@this.Session()).StandardRate;
            var overtimeRate = new RateTypes(@this.Session()).OvertimeRate;

            var frequencies = new TimeFrequencies(@this.Session());

            var timeEntryYesterday1 = workOrder.CreateTimeEntry(yesterday, laterYesterday, frequencies.Day, standardRate);
            var timeEntryToday1     = workOrder.CreateTimeEntry(today, laterToday, frequencies.Hour, standardRate);
            var timeEntryTomorrow1  = workOrder.CreateTimeEntry(tomorrow, laterTomorrow, frequencies.Minute, overtimeRate);

            allorsEmployee1.TimeSheetWhereWorker.AddTimeEntry(timeEntryYesterday1);
            allorsEmployee1.TimeSheetWhereWorker.AddTimeEntry(timeEntryToday1);
            allorsEmployee1.TimeSheetWhereWorker.AddTimeEntry(timeEntryTomorrow1);

            var timeEntryYesterday2 = workOrder.CreateTimeEntry(yesterday, laterYesterday, frequencies.Day, standardRate);
            var timeEntryToday2     = workOrder.CreateTimeEntry(today, laterToday, frequencies.Hour, standardRate);
            var timeEntryTomorrow2  = workOrder.CreateTimeEntry(tomorrow, laterTomorrow, frequencies.Minute, overtimeRate);

            allorsEmployee2.TimeSheetWhereWorker.AddTimeEntry(timeEntryYesterday2);
            allorsEmployee2.TimeSheetWhereWorker.AddTimeEntry(timeEntryToday2);
            allorsEmployee2.TimeSheetWhereWorker.AddTimeEntry(timeEntryTomorrow2);

            var po = new PurchaseOrders(@this.Session()).Extent().First;

            foreach (PurchaseOrderItem purchaseOrderItem in po.PurchaseOrderItems)
            {
                new WorkEffortPurchaseOrderItemAssignmentBuilder(@this.Session())
                .WithPurchaseOrderItem(purchaseOrderItem)
                .WithAssignment(workOrder)
                .WithQuantity(1)
                .Build();
            }

            @this.Session().Derive();
        }
Ejemplo n.º 19
0
        public SalesInvoice AppsCredit(SalesInvoiceCredit method)
        {
            var salesInvoice = new SalesInvoiceBuilder(this.Strategy.Session)
                               .WithPurchaseInvoice(this.PurchaseInvoice)
                               .WithBilledFrom(this.BilledFrom)
                               .WithBilledFromContactMechanism(this.BilledFromContactMechanism)
                               .WithBilledFromContactPerson(this.BilledFromContactPerson)
                               .WithBillToCustomer(this.BillToCustomer)
                               .WithBillToContactMechanism(this.BillToContactMechanism)
                               .WithBillToContactPerson(this.BillToContactPerson)
                               .WithBillToEndCustomer(this.BillToEndCustomer)
                               .WithBillToEndCustomerContactMechanism(this.BillToEndCustomerContactMechanism)
                               .WithBillToEndCustomerContactPerson(this.BillToEndCustomerContactPerson)
                               .WithShipToCustomer(this.ShipToCustomer)
                               .WithShipToAddress(this.ShipToAddress)
                               .WithShipToContactPerson(this.ShipToContactPerson)
                               .WithShipToEndCustomer(this.ShipToEndCustomer)
                               .WithShipToEndCustomerAddress(this.ShipToEndCustomerAddress)
                               .WithShipToEndCustomerContactPerson(this.ShipToEndCustomerContactPerson)
                               .WithDescription(this.Description)
                               .WithStore(this.Store)
                               .WithInvoiceDate(DateTime.UtcNow)
                               .WithSalesChannel(this.SalesChannel)
                               .WithSalesInvoiceType(new SalesInvoiceTypes(this.Strategy.Session).CreditNote)
                               .WithVatRegime(this.VatRegime)
                               .WithDiscountAdjustment(this.DiscountAdjustment)
                               .WithSurchargeAdjustment(this.SurchargeAdjustment)
                               .WithShippingAndHandlingCharge(this.ShippingAndHandlingCharge)
                               .WithCustomerReference(this.CustomerReference)
                               .WithPaymentMethod(this.PaymentMethod)
                               .WithBillingAccount(this.BillingAccount)
                               .Build();

            if (this.ExistDiscountAdjustment)
            {
                salesInvoice.DiscountAdjustment = new DiscountAdjustmentBuilder(this.strategy.Session).WithAmount(this.DiscountAdjustment.Amount * -1).Build();
            }

            if (this.ExistSurchargeAdjustment)
            {
                salesInvoice.SurchargeAdjustment = new SurchargeAdjustmentBuilder(this.strategy.Session).WithAmount(this.SurchargeAdjustment.Amount * -1).Build();
            }

            foreach (SalesInvoiceItem salesInvoiceItem in this.SalesInvoiceItems)
            {
                var invoiceItem = new SalesInvoiceItemBuilder(this.Strategy.Session)
                                  .WithInvoiceItemType(salesInvoiceItem.InvoiceItemType)
                                  .WithActualUnitPrice(salesInvoiceItem.ActualUnitPrice * -1)
                                  .WithProduct(salesInvoiceItem.Product)
                                  .WithProductFeature(salesInvoiceItem.ProductFeature)
                                  .WithQuantity(salesInvoiceItem.Quantity)
                                  .WithDescription(salesInvoiceItem.Description)
                                  .WithSerialisedItem(salesInvoiceItem.SerialisedItem)
                                  .WithComment(salesInvoiceItem.Comment)
                                  .WithDetails(salesInvoiceItem.Details)
                                  .WithInternalComment(salesInvoiceItem.InternalComment)
                                  .WithFacility(salesInvoiceItem.Facility)
                                  .WithAssignedVatRegime(salesInvoiceItem.AssignedVatRegime)
                                  .Build();

                salesInvoice.AddSalesInvoiceItem(invoiceItem);
            }

            return(salesInvoice);
        }
Ejemplo n.º 20
0
        public SalesInvoice AppsCopy(SalesInvoiceCopy method)
        {
            var salesInvoice = new SalesInvoiceBuilder(this.Strategy.Session)
                               .WithPurchaseInvoice(this.PurchaseInvoice)
                               .WithBilledFrom(this.BilledFrom)
                               .WithBilledFromContactMechanism(this.BilledFromContactMechanism)
                               .WithBilledFromContactPerson(this.BilledFromContactPerson)
                               .WithBillToCustomer(this.BillToCustomer)
                               .WithBillToContactMechanism(this.BillToContactMechanism)
                               .WithBillToContactPerson(this.BillToContactPerson)
                               .WithBillToEndCustomer(this.BillToEndCustomer)
                               .WithBillToEndCustomerContactMechanism(this.BillToEndCustomerContactMechanism)
                               .WithBillToEndCustomerContactPerson(this.BillToEndCustomerContactPerson)
                               .WithShipToCustomer(this.ShipToCustomer)
                               .WithShipToAddress(this.ShipToAddress)
                               .WithShipToContactPerson(this.ShipToContactPerson)
                               .WithShipToEndCustomer(this.ShipToEndCustomer)
                               .WithShipToEndCustomerAddress(this.ShipToEndCustomerAddress)
                               .WithShipToEndCustomerContactPerson(this.ShipToEndCustomerContactPerson)
                               .WithDescription(this.Description)
                               .WithStore(this.Store)
                               .WithInvoiceDate(DateTime.UtcNow)
                               .WithSalesChannel(this.SalesChannel)
                               .WithSalesInvoiceType(new SalesInvoiceTypes(this.Strategy.Session).SalesInvoice)
                               .WithVatRegime(this.VatRegime)
                               .WithDiscountAdjustment(this.DiscountAdjustment)
                               .WithSurchargeAdjustment(this.SurchargeAdjustment)
                               .WithShippingAndHandlingCharge(this.ShippingAndHandlingCharge)
                               .WithFee(this.Fee)
                               .WithCustomerReference(this.CustomerReference)
                               .WithPaymentMethod(this.PaymentMethod)
                               .WithComment(this.Comment)
                               .WithInternalComment(this.InternalComment)
                               .WithMessage(this.Message)
                               .WithBillingAccount(this.BillingAccount)
                               .Build();

            foreach (SalesInvoiceItem salesInvoiceItem in this.SalesInvoiceItems)
            {
                var invoiceItem = new SalesInvoiceItemBuilder(this.Strategy.Session)
                                  .WithInvoiceItemType(salesInvoiceItem.InvoiceItemType)
                                  .WithActualUnitPrice(salesInvoiceItem.ActualUnitPrice)
                                  .WithProduct(salesInvoiceItem.Product)
                                  .WithProductFeature(salesInvoiceItem.ProductFeature)
                                  .WithQuantity(salesInvoiceItem.Quantity)
                                  .WithDescription(salesInvoiceItem.Description)
                                  .WithSerialisedItem(salesInvoiceItem.SerialisedItem)
                                  .WithComment(salesInvoiceItem.Comment)
                                  .WithDetails(salesInvoiceItem.Details)
                                  .WithInternalComment(salesInvoiceItem.InternalComment)
                                  .WithMessage(salesInvoiceItem.Message)
                                  .WithFacility(salesInvoiceItem.Facility)
                                  .Build();

                salesInvoice.AddSalesInvoiceItem(invoiceItem);

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

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

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

            foreach (SalesTerm salesTerm in this.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());
                }
            }

            return(salesInvoice);
        }
Ejemplo n.º 21
0
        public static void BaseMonthly(ISession session)
        {
            var customers = new Parties(session).Extent();

            customers.Filter.AddEquals(M.Party.CollectiveWorkEffortInvoice, true);

            var workTasks = new WorkTasks(session).Extent();

            workTasks.Filter.AddEquals(M.WorkEffort.WorkEffortState, new WorkEffortStates(session).Completed);
            workTasks.Filter.AddContainedIn(M.WorkEffort.Customer, (Extent)customers);

            var workTasksByCustomer = workTasks.Select(v => v.Customer).Distinct()
                                      .ToDictionary(v => v, v => v.WorkEffortsWhereCustomer.Where(w => w.WorkEffortState.Equals(new WorkEffortStates(session).Completed)).ToArray());

            SalesInvoice salesInvoice = null;

            foreach (var customerWorkTasks in workTasksByCustomer)
            {
                var customer = customerWorkTasks.Key;

                var customerWorkTasksByInternalOrganisation = customerWorkTasks.Value
                                                              .GroupBy(v => v.TakenBy)
                                                              .Select(v => v)
                                                              .ToArray();

                if (customerWorkTasks.Value.Any(v => v.CanInvoice))
                {
                    foreach (var group in customerWorkTasksByInternalOrganisation)
                    {
                        if (group.Any(v => v.CanInvoice))
                        {
                            salesInvoice = new SalesInvoiceBuilder(session)
                                           .WithBilledFrom(group.Key)
                                           .WithBillToCustomer(customer)
                                           .WithInvoiceDate(session.Now())
                                           .WithSalesInvoiceType(new SalesInvoiceTypes(session).SalesInvoice)
                                           .Build();
                        }

                        var timeEntriesByBillingRate = group.SelectMany(v => v.ServiceEntriesWhereWorkEffort.OfType <TimeEntry>())
                                                       .Where(v => (v.IsBillable && !v.BillableAmountOfTime.HasValue && v.AmountOfTime.HasValue) || v.BillableAmountOfTime.HasValue)
                                                       .GroupBy(v => v.BillingRate)
                                                       .Select(v => v)
                                                       .ToArray();

                        foreach (var rateGroup in timeEntriesByBillingRate)
                        {
                            var timeEntries = rateGroup.ToArray();

                            var invoiceItem = new SalesInvoiceItemBuilder(session)
                                              .WithInvoiceItemType(new InvoiceItemTypes(session).Service)
                                              .WithAssignedUnitPrice(rateGroup.Key)
                                              .WithQuantity(timeEntries.Sum(v => v.BillableAmountOfTime ?? v.AmountOfTime ?? 0.0m))
                                              .Build();

                            salesInvoice.AddSalesInvoiceItem(invoiceItem);

                            foreach (var billableEntry in timeEntries)
                            {
                                new TimeEntryBillingBuilder(session)
                                .WithTimeEntry(billableEntry)
                                .WithInvoiceItem(invoiceItem)
                                .Build();
                            }
                        }

                        foreach (var workEffort in group)
                        {
                            if (workEffort.CanInvoice)
                            {
                                if (string.IsNullOrEmpty(salesInvoice.CustomerReference))
                                {
                                    salesInvoice.CustomerReference = $"WorkOrder(s): {workEffort.WorkEffortNumber}";
                                }
                                else
                                {
                                    salesInvoice.CustomerReference += $", {workEffort.WorkEffortNumber}";
                                }

                                foreach (WorkEffortInventoryAssignment inventoryAssignment in workEffort.WorkEffortInventoryAssignmentsWhereAssignment)
                                {
                                    var part = inventoryAssignment.InventoryItem.Part;

                                    var invoiceItem = new SalesInvoiceItemBuilder(session)
                                                      .WithInvoiceItemType(new InvoiceItemTypes(session).PartItem)
                                                      .WithPart(part)
                                                      .WithAssignedUnitPrice(inventoryAssignment.UnitSellingPrice)
                                                      .WithQuantity(inventoryAssignment.DerivedBillableQuantity)
                                                      .Build();

                                    salesInvoice.AddSalesInvoiceItem(invoiceItem);

                                    new WorkEffortBillingBuilder(session)
                                    .WithWorkEffort(workEffort)
                                    .WithInvoiceItem(invoiceItem)
                                    .Build();
                                }

                                foreach (WorkEffortPurchaseOrderItemAssignment purchaseOrderItemAssignment in workEffort.WorkEffortPurchaseOrderItemAssignmentsWhereAssignment)
                                {
                                    var invoiceItem = new SalesInvoiceItemBuilder(session)
                                                      .WithInvoiceItemType(new InvoiceItemTypes(session).Service)
                                                      .WithAssignedUnitPrice(purchaseOrderItemAssignment.UnitSellingPrice)
                                                      .WithQuantity(purchaseOrderItemAssignment.Quantity)
                                                      .Build();

                                    salesInvoice.AddSalesInvoiceItem(invoiceItem);

                                    new WorkEffortBillingBuilder(session)
                                    .WithWorkEffort(workEffort)
                                    .WithInvoiceItem(invoiceItem)
                                    .Build();
                                }

                                workEffort.WorkEffortState = new WorkEffortStates(session).Finished;
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 22
0
        public void GivenSalesInvoice_WhenDerivingSalesReps_ThenSalesRepsAreCollectedFromSalesInvoiceItems()
        {
            var salesrep1 = new PersonBuilder(this.DatabaseSession).WithLastName("salesrep for child product category").Build();
            var salesrep2 = new PersonBuilder(this.DatabaseSession).WithLastName("salesrep for parent category").Build();
            var salesrep3 = new PersonBuilder(this.DatabaseSession).WithLastName("salesrep for everything else").Build();
            var parentProductCategory = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("parent").Build();
            var childProductCategory = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("child").WithParent(parentProductCategory).Build();

            var billToCustomer = new OrganisationBuilder(this.DatabaseSession).WithName("customer").Build();
            var contactMechanism = new PostalAddressBuilder(this.DatabaseSession)
                .WithAddress1("Haverwerf 15")
                .WithPostalBoundary(new PostalBoundaryBuilder(this.DatabaseSession)
                                        .WithLocality("Mechelen")
                                        .WithCountry(new Countries(this.DatabaseSession).FindBy(Countries.Meta.IsoCode, "BE"))
                                        .Build())

                .Build();

            new SalesRepRelationshipBuilder(this.DatabaseSession)
                .WithSalesRepresentative(salesrep1)
                .WithCustomer(billToCustomer)
                .WithProductCategory(childProductCategory)
                .Build();

            new SalesRepRelationshipBuilder(this.DatabaseSession)
                .WithSalesRepresentative(salesrep2)
                .WithCustomer(billToCustomer)
                .WithProductCategory(parentProductCategory)
                .Build();

            new SalesRepRelationshipBuilder(this.DatabaseSession)
                .WithSalesRepresentative(salesrep3)
                .WithCustomer(billToCustomer)
                .Build();

            var good1 = new GoodBuilder(this.DatabaseSession)
                .WithSku("10101")
                .WithName("good")
                .WithVatRate(new VatRateBuilder(this.DatabaseSession).WithRate(0).Build())
                .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .WithProductCategory(childProductCategory)
                .Build();

            var good2 = new GoodBuilder(this.DatabaseSession)
                .WithSku("10101")
                .WithName("good")
                .WithVatRate(new VatRateBuilder(this.DatabaseSession).WithRate(0).Build())
                .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .WithProductCategory(parentProductCategory)
                .Build();

            var good3 = new GoodBuilder(this.DatabaseSession)
                .WithSku("10101")
                .WithName("good")
                .WithVatRate(new VatRateBuilder(this.DatabaseSession).WithRate(0).Build())
                .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .Build();

            var invoice = new SalesInvoiceBuilder(this.DatabaseSession)
                .WithBillToCustomer(billToCustomer)
                .WithBillToContactMechanism(contactMechanism)
                .Build();

            new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(invoice.BillToCustomer).WithInternalOrganisation(Singleton.Instance(this.DatabaseSession).DefaultInternalOrganisation).Build();

            var item1 = new SalesInvoiceItemBuilder(this.DatabaseSession)
                .WithProduct(good1)
                .WithSalesInvoiceItemType(new SalesInvoiceItemTypes(this.DatabaseSession).ProductItem)
                .WithQuantity(3)
                .WithActualUnitPrice(5)
                .Build();

            var item2 = new SalesInvoiceItemBuilder(this.DatabaseSession)
                .WithProduct(good2)
                .WithSalesInvoiceItemType(new SalesInvoiceItemTypes(this.DatabaseSession).ProductItem)
                .WithQuantity(3)
                .WithActualUnitPrice(5)
                .Build();

            var item3 = new SalesInvoiceItemBuilder(this.DatabaseSession)
                .WithProduct(good3)
                .WithSalesInvoiceItemType(new SalesInvoiceItemTypes(this.DatabaseSession).ProductItem)
                .WithQuantity(3)
                .WithActualUnitPrice(5)
                .Build();

            invoice.AddSalesInvoiceItem(item1);

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(1, invoice.SalesReps.Count);
            Assert.Contains(salesrep1, invoice.SalesReps);

            invoice.AddSalesInvoiceItem(item2);

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(2, invoice.SalesReps.Count);
            Assert.Contains(salesrep1, invoice.SalesReps);
            Assert.Contains(salesrep2, invoice.SalesReps);

            invoice.AddSalesInvoiceItem(item3);

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(3, invoice.SalesReps.Count);
            Assert.Contains(salesrep1, invoice.SalesReps);
            Assert.Contains(salesrep2, invoice.SalesReps);
            Assert.Contains(salesrep3, invoice.SalesReps);
        }
Ejemplo n.º 23
0
        public void GivenInvoiceItemForFeature1_WhenDerivingPrices_ThenUsePriceComponentsForFeature1()
        {
            this.InstantiateObjects(this.DatabaseSession);

            const decimal quantity = 3;
            var item1 = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProductFeature(this.feature1).WithSalesInvoiceItemType(new SalesInvoiceItemTypes(this.DatabaseSession).ProductFeatureItem).WithQuantity(quantity).Build();
            this.invoice.AddSalesInvoiceItem(item1);

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(this.currentFeature1BasePrice.Price, item1.UnitBasePrice);
            Assert.AreEqual(0, item1.UnitDiscount);
            Assert.AreEqual(0, item1.UnitSurcharge);
            Assert.AreEqual(this.currentFeature1BasePrice.Price, item1.CalculatedUnitPrice);
            Assert.AreEqual(this.currentFeature1BasePrice.Price * quantity, item1.TotalBasePrice);
            Assert.AreEqual(0, item1.TotalDiscount);
            Assert.AreEqual(0, item1.TotalSurcharge);
            Assert.AreEqual(this.currentFeature1BasePrice.Price * quantity, item1.TotalExVat);

            Assert.AreEqual(this.currentFeature1BasePrice.Price * quantity, this.invoice.TotalBasePrice);
            Assert.AreEqual(0, this.invoice.TotalDiscount);
            Assert.AreEqual(0, this.invoice.TotalSurcharge);
            Assert.AreEqual(this.currentFeature1BasePrice.Price * quantity, this.invoice.TotalExVat);
        }
Ejemplo n.º 24
0
        public void GivenPurchasePriceInDifferenUnitOfMeasureComparedToProduct_WhenDerivingMarkupAndProfitMargin_ThenUnitOfMeasureConversionIsPerformed()
        {
            var pair = new UnitsOfMeasure(this.DatabaseSession).Pair;
            var piece = new UnitsOfMeasure(this.DatabaseSession).Piece;

            var fromPairToPiece = new UnitOfMeasureConversionBuilder(this.DatabaseSession)
                .WithToUnitOfMeasure(piece)
                .WithConversionFactor(2).Build();

            var fromPieceToPair = new UnitOfMeasureConversionBuilder(this.DatabaseSession)
                .WithToUnitOfMeasure(pair)
                .WithConversionFactor(0.5M).Build();

            pair.AddUnitOfMeasureConversion(fromPairToPiece);
            pair.AddUnitOfMeasureConversion(fromPieceToPair);

            this.goodPurchasePrice.UnitOfMeasure = pair;
            this.good.UnitOfMeasure = piece;

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

            this.InstantiateObjects(this.DatabaseSession);

            const decimal quantity = 3;
            var item1 = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(this.good).WithSalesInvoiceItemType(new SalesInvoiceItemTypes(this.DatabaseSession).ProductItem).WithQuantity(quantity).Build();
            this.invoice.AddSalesInvoiceItem(item1);

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(this.currentGood1BasePrice.Price, item1.UnitBasePrice);
            Assert.AreEqual(0, item1.UnitDiscount);
            Assert.AreEqual(0, item1.UnitSurcharge);
            Assert.AreEqual(this.currentGood1BasePrice.Price, item1.CalculatedUnitPrice);
            Assert.AreEqual(decimal.Round((item1.CalculatedUnitPrice * this.vatRate21.Rate) / 100, 2), item1.UnitVat);
            Assert.AreEqual(this.goodPurchasePrice.Price * 0.5M, item1.UnitPurchasePrice);

            Assert.AreEqual(this.currentGood1BasePrice.Price * quantity, item1.TotalBasePrice);
            Assert.AreEqual(0, item1.TotalDiscount);
            Assert.AreEqual(0, item1.TotalSurcharge);
            Assert.AreEqual(this.currentGood1BasePrice.Price * quantity, item1.TotalExVat);
            Assert.AreEqual(decimal.Round((item1.CalculatedUnitPrice * this.vatRate21.Rate) / 100, 2) * quantity, item1.TotalVat);

            var purchasePrice = this.goodPurchasePrice.Price * 0.5M;

            Assert.AreEqual(decimal.Round(((item1.UnitBasePrice / purchasePrice) - 1) * 100, 2), item1.InitialMarkupPercentage);
            Assert.AreEqual(decimal.Round(((item1.CalculatedUnitPrice / purchasePrice) - 1) * 100, 2), item1.MaintainedMarkupPercentage);
            Assert.AreEqual(decimal.Round(((item1.UnitBasePrice - purchasePrice) / item1.UnitBasePrice) * 100, 2), item1.InitialProfitMargin);
            Assert.AreEqual(decimal.Round(((item1.CalculatedUnitPrice - purchasePrice) / item1.CalculatedUnitPrice) * 100, 2), item1.MaintainedProfitMargin);

            Assert.AreEqual(this.currentGood1BasePrice.Price * quantity, this.invoice.TotalBasePrice);
            Assert.AreEqual(0, this.invoice.TotalDiscount);
            Assert.AreEqual(0, this.invoice.TotalSurcharge);
            Assert.AreEqual(this.currentGood1BasePrice.Price * quantity, this.invoice.TotalExVat);
            Assert.AreEqual(decimal.Round((item1.CalculatedUnitPrice * this.vatRate21.Rate) / 100, 2) * quantity, this.invoice.TotalVat);
            Assert.AreEqual(item1.UnitPurchasePrice, this.invoice.TotalPurchasePrice);
        }
Ejemplo n.º 25
0
        public void AppsOnDeriveInvoices(IDerivation derivation)
        {
            var invoiceByOrder = new Dictionary<Allors.Domain.SalesOrder, Allors.Domain.SalesInvoice>();
            var costsInvoiced = false;

            foreach (ShipmentItem shipmentItem in this.ShipmentItems)
            {
                foreach (OrderShipment orderShipment in shipmentItem.OrderShipmentsWhereShipmentItem)
                {
                    var salesOrder = orderShipment.SalesOrderItem.SalesOrderWhereSalesOrderItem;

                    Allors.Domain.SalesInvoice salesInvoice;
                    if (!invoiceByOrder.TryGetValue(salesOrder, out salesInvoice))
                    {
                        salesInvoice = new SalesInvoiceBuilder(this.Strategy.Session)
                            .WithStore(salesOrder.Store)
                            .WithInvoiceDate(DateTime.UtcNow)
                            .WithSalesChannel(salesOrder.SalesChannel)
                            .WithSalesInvoiceType(new Allors.Domain.SalesInvoiceTypes(this.Strategy.Session).SalesInvoice)
                            .WithVatRegime(salesOrder.VatRegime)
                            .WithBilledFromContactMechanism(this.BillFromContactMechanism)
                            .WithBilledFromInternalOrganisation(this.BillFromInternalOrganisation)
                            .WithBillToContactMechanism(this.BillToContactMechanism)
                            .WithBillToCustomer(this.BillToParty)
                            .WithShipToCustomer(this.ShipToParty)
                            .WithShipToAddress(this.ShipToAddress)
                            .WithDiscountAdjustment(salesOrder.DiscountAdjustment)
                            .WithSurchargeAdjustment(salesOrder.SurchargeAdjustment)
                            .WithShippingAndHandlingCharge(salesOrder.ShippingAndHandlingCharge)
                            .WithFee(salesOrder.Fee)
                            .WithCustomerReference(salesOrder.CustomerReference)
                            .WithPaymentMethod(this.PaymentMethod)
                            .Build();

                        invoiceByOrder.Add(salesOrder, salesInvoice);

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

                    var invoiceItem = new SalesInvoiceItemBuilder(this.Strategy.Session)
                        .WithSalesInvoiceItemType(new Allors.Domain.SalesInvoiceItemTypes(this.Strategy.Session).ProductItem)
                        .WithProduct(orderShipment.SalesOrderItem.Product)
                        .WithQuantity(orderShipment.Quantity)
                        .Build();

                    salesInvoice.AddSalesInvoiceItem(invoiceItem);
                    shipmentItem.AddInvoiceItem(invoiceItem);
                }

                foreach (var keyValuePair in invoiceByOrder)
                {
                    // TODO: put this in prepare
                    // keyValuePair.Value.Derive(x=>x.WithDerivation(derivation));
                }
            }
        }
Ejemplo n.º 26
0
        public void GivenInvoiceItemWithDiscountAmountForSalesType_WhenDeriving_ThenUseDiscountComponentsForSalesType()
        {
            const decimal quantity = 3;
            const decimal amount = 1;

            new DiscountComponentBuilder(this.DatabaseSession)
                .WithSpecifiedFor(this.internalOrganisation)
                .WithDescription("discount good for sales type")
                .WithSalesChannel(new SalesChannels(this.DatabaseSession).EmailChannel)
                .WithProduct(this.good)
                .WithPrice(amount)
                .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).WithProduct(this.good).WithSalesInvoiceItemType(new SalesInvoiceItemTypes(this.DatabaseSession).ProductItem).WithQuantity(quantity).Build();
            this.invoice.AddSalesInvoiceItem(item1);

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(this.currentGood1BasePrice.Price, item1.UnitBasePrice);
            Assert.AreEqual(amount, item1.UnitDiscount);
            Assert.AreEqual(0, item1.UnitSurcharge);
            Assert.AreEqual(this.currentGood1BasePrice.Price - amount, 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.º 27
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.º 28
0
        public void GivenInvoiceItemWithDiscountPercentageForOrderValue_WhenDeriving_ThenUseDiscountComponentsForOrderValue()
        {
            const decimal quantity1 = 3;
            const decimal quantity2 = 3;
            const decimal quantity3 = 10;
            const decimal percentage1 = 5;
            const decimal percentage2 = 10;

            var value1 = new OrderValueBuilder(this.DatabaseSession).WithFromAmount(50).WithThroughAmount(99).Build();
            var value2 = new OrderValueBuilder(this.DatabaseSession).WithFromAmount(100).Build();

            new DiscountComponentBuilder(this.DatabaseSession)
                .WithSpecifiedFor(this.internalOrganisation)
                .WithDescription("discount good for order value 1")
                .WithOrderValue(value1)
                .WithProduct(this.good)
                .WithPercentage(percentage1)
                .WithFromDate(DateTime.UtcNow.AddMinutes(-1))
                .WithThroughDate(DateTime.UtcNow.AddYears(1).AddDays(-1))
                .Build();

            new DiscountComponentBuilder(this.DatabaseSession)
                .WithSpecifiedFor(this.internalOrganisation)
                .WithDescription("discount good for order value 1")
                .WithOrderValue(value2)
                .WithProduct(this.good)
                .WithPercentage(percentage2)
                .WithFromDate(DateTime.UtcNow.AddMinutes(-1))
                .WithThroughDate(DateTime.UtcNow.AddYears(1).AddDays(-1))
                .Build();

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

            this.InstantiateObjects(this.DatabaseSession);

            var item1 = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(this.good).WithSalesInvoiceItemType(new SalesInvoiceItemTypes(this.DatabaseSession).ProductItem).WithQuantity(quantity1).Build();
            this.invoice.AddSalesInvoiceItem(item1);

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(this.currentGood1BasePrice.Price, item1.UnitBasePrice);
            Assert.AreEqual(0, item1.UnitDiscount);
            Assert.AreEqual(0, item1.UnitSurcharge);
            Assert.AreEqual(this.currentGood1BasePrice.Price, 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);

            var item2 = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(this.good).WithSalesInvoiceItemType(new SalesInvoiceItemTypes(this.DatabaseSession).ProductItem).WithQuantity(quantity2).Build();
            this.invoice.AddSalesInvoiceItem(item2);

            this.DatabaseSession.Derive(true);

            var amount1 = decimal.Round((this.currentGood1BasePrice.Price * percentage1) / 100, 2);
            Assert.AreEqual(this.currentGood1BasePrice.Price, item1.UnitBasePrice);
            Assert.AreEqual(amount1, item1.UnitDiscount);
            Assert.AreEqual(0, item1.UnitSurcharge);
            Assert.AreEqual(this.currentGood1BasePrice.Price - amount1, 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);

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

            Assert.AreEqual(decimal.Round(((item2.UnitBasePrice / this.goodPurchasePrice.Price) - 1) * 100, 2), item2.InitialMarkupPercentage);
            Assert.AreEqual(decimal.Round(((item2.CalculatedUnitPrice / this.goodPurchasePrice.Price) - 1) * 100, 2), item2.MaintainedMarkupPercentage);
            Assert.AreEqual(decimal.Round(((item2.UnitBasePrice - this.goodPurchasePrice.Price) / item2.UnitBasePrice) * 100, 2), item2.InitialProfitMargin);
            Assert.AreEqual(decimal.Round(((item2.CalculatedUnitPrice - this.goodPurchasePrice.Price) / item2.CalculatedUnitPrice) * 100, 2), item2.MaintainedProfitMargin);

            var item3 = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(this.good).WithSalesInvoiceItemType(new SalesInvoiceItemTypes(this.DatabaseSession).ProductItem).WithQuantity(quantity3).Build();
            this.invoice.AddSalesInvoiceItem(item3);

            this.DatabaseSession.Derive(true);

            var amount2 = decimal.Round((this.currentGood1BasePrice.Price * percentage2) / 100, 2);
            Assert.AreEqual(this.currentGood1BasePrice.Price, item1.UnitBasePrice);
            Assert.AreEqual(amount2, item1.UnitDiscount);
            Assert.AreEqual(0, item1.UnitSurcharge);
            Assert.AreEqual(this.currentGood1BasePrice.Price - amount2, 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);

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

            Assert.AreEqual(decimal.Round(((item2.UnitBasePrice / this.goodPurchasePrice.Price) - 1) * 100, 2), item2.InitialMarkupPercentage);
            Assert.AreEqual(decimal.Round(((item2.CalculatedUnitPrice / this.goodPurchasePrice.Price) - 1) * 100, 2), item2.MaintainedMarkupPercentage);
            Assert.AreEqual(decimal.Round(((item2.UnitBasePrice - this.goodPurchasePrice.Price) / item2.UnitBasePrice) * 100, 2), item2.InitialProfitMargin);
            Assert.AreEqual(decimal.Round(((item2.CalculatedUnitPrice - this.goodPurchasePrice.Price) / item2.CalculatedUnitPrice) * 100, 2), item2.MaintainedProfitMargin);

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

            Assert.AreEqual(decimal.Round(((item3.UnitBasePrice / this.goodPurchasePrice.Price) - 1) * 100, 2), item3.InitialMarkupPercentage);
            Assert.AreEqual(decimal.Round(((item3.CalculatedUnitPrice / this.goodPurchasePrice.Price) - 1) * 100, 2), item3.MaintainedMarkupPercentage);
            Assert.AreEqual(decimal.Round(((item3.UnitBasePrice - this.goodPurchasePrice.Price) / item3.UnitBasePrice) * 100, 2), item3.InitialProfitMargin);
            Assert.AreEqual(decimal.Round(((item3.CalculatedUnitPrice - this.goodPurchasePrice.Price) / item3.CalculatedUnitPrice) * 100, 2), item3.MaintainedProfitMargin);
        }
Ejemplo n.º 29
0
        public void GivenSalesInvoice_WhenDeriving_ThenRevenuesAreCreatedAndUpdated()
        {
            var productItem = new SalesInvoiceItemTypes(this.DatabaseSession).ProductItem;
            var contactMechanism = new ContactMechanisms(this.DatabaseSession).Extent().First;

            var customer1 = new OrganisationBuilder(this.DatabaseSession).WithName("customer1").Build();
            var customer2 = new OrganisationBuilder(this.DatabaseSession).WithName("customer2").Build();
            var salesRep1 = new PersonBuilder(this.DatabaseSession).WithLastName("salesRep1").Build();
            var salesRep2 = new PersonBuilder(this.DatabaseSession).WithLastName("salesRep2").Build();
            var catMain = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("main cat").Build();
            var cat1 = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("cat for good1").WithParent(catMain).Build();
            var cat2 = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("cat for good2").WithParent(catMain).Build();

            new SalesRepRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer1).WithProductCategory(cat1).WithSalesRepresentative(salesRep1).Build();
            new SalesRepRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer1).WithProductCategory(cat2).WithSalesRepresentative(salesRep2).Build();

            this.DatabaseSession.Derive(true);

            new SalesRepRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer2).WithProductCategory(cat1).WithSalesRepresentative(salesRep1).Build();
            new SalesRepRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer2).WithProductCategory(cat2).WithSalesRepresentative(salesRep2).Build();

            this.DatabaseSession.Derive(true);

            var euro = new Currencies(this.DatabaseSession).FindBy(Currencies.Meta.IsoCode, "EUR");
            var vatRate21 = new VatRateBuilder(this.DatabaseSession).WithRate(21).Build();

            var good1 = new GoodBuilder(this.DatabaseSession)
                .WithSku("10101")
                .WithVatRate(vatRate21)
                .WithName("good1")
                .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .WithPrimaryProductCategory(cat1)
                .Build();

            var good2 = new GoodBuilder(this.DatabaseSession)
                .WithSku("10102")
                .WithVatRate(vatRate21)
                .WithName("good2")
                .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .WithPrimaryProductCategory(cat2)
                .Build();

            var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation");
            internalOrganisation.PreferredCurrency = euro;

            var invoice1 = new SalesInvoiceBuilder(this.DatabaseSession)
                .WithInvoiceDate(DateTime.UtcNow)
                .WithInvoiceNumber("1")
                .WithBillToCustomer(customer1)
                .WithBillToContactMechanism(contactMechanism)
                .WithSalesChannel(new SalesChannels(this.DatabaseSession).WebChannel)
                .WithSalesInvoiceType(new SalesInvoiceTypes(this.DatabaseSession).SalesInvoice)
                .Build();

            new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(invoice1.BillToCustomer).WithInternalOrganisation(Singleton.Instance(this.DatabaseSession).DefaultInternalOrganisation).Build();

            var item1 = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantity(3).WithActualUnitPrice(15).WithSalesInvoiceItemType(productItem).Build();
            invoice1.AddSalesInvoiceItem(item1);

            var item2 = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantity(3).WithActualUnitPrice(15).WithSalesInvoiceItemType(productItem).Build();
            invoice1.AddSalesInvoiceItem(item2);

            var item3 = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good2).WithQuantity(5).WithActualUnitPrice(10).WithSalesInvoiceItemType(productItem).Build();
            invoice1.AddSalesInvoiceItem(item3);

            this.DatabaseSession.Derive(true);

            var customer1Revenue = customer1.PartyRevenuesWhereParty[0];
            var internalOrganisationRevenue = internalOrganisation.InternalOrganisationRevenuesWhereInternalOrganisation[0];
            var storeRevenue = invoice1.Store.StoreRevenuesWhereStore[0];
            var salesChannelRevenue = invoice1.SalesChannel.SalesChannelRevenuesWhereSalesChannel[0];
            var salesRep1Revenue = salesRep1.SalesRepRevenuesWhereSalesRep[0];
            var salesRep2Revenue = salesRep2.SalesRepRevenuesWhereSalesRep[0];
            var good1Revenue = good1.ProductRevenuesWhereProduct[0];
            var good2Revenue = good2.ProductRevenuesWhereProduct[0];
            var cat1Revenue = cat1.ProductCategoryRevenuesWhereProductCategory[0];
            var cat2Revenue = cat2.ProductCategoryRevenuesWhereProductCategory[0];
            var catMainRevenue = catMain.ProductCategoryRevenuesWhereProductCategory[0];

            var customer1ProductRevenues = customer1.PartyProductRevenuesWhereParty;
            Assert.AreEqual(2, customer1ProductRevenues.Count);

            customer1ProductRevenues = customer1.PartyProductRevenuesWhereParty;
            customer1ProductRevenues.Filter.AddEquals(PartyProductRevenues.Meta.Product, good1);
            var customer1Good1Revenue = customer1ProductRevenues.First;

            customer1ProductRevenues = customer1.PartyProductRevenuesWhereParty;
            customer1ProductRevenues.Filter.AddEquals(PartyProductRevenues.Meta.Product, good2);
            var customer1Good2Revenue = customer1ProductRevenues.First;

            var customer1ProductCategoryRevenues = customer1.PartyProductCategoryRevenuesWhereParty;
            Assert.AreEqual(3, customer1ProductCategoryRevenues.Count);

            customer1ProductCategoryRevenues.Filter.AddEquals(PartyProductCategoryRevenues.Meta.ProductCategory, cat1);
            var customer1Cat1Revenue = customer1ProductCategoryRevenues.First;

            customer1ProductCategoryRevenues = customer1.PartyProductCategoryRevenuesWhereParty;
            customer1ProductCategoryRevenues.Filter.AddEquals(PartyProductCategoryRevenues.Meta.ProductCategory, cat2);
            var customer1Cat2Revenue = customer1ProductCategoryRevenues.First;

            customer1ProductCategoryRevenues = customer1.PartyProductCategoryRevenuesWhereParty;
            customer1ProductCategoryRevenues.Filter.AddEquals(PartyProductCategoryRevenues.Meta.ProductCategory, catMain);
            var customer1CatMainRevenue = customer1ProductCategoryRevenues.First;

            var salesRep1Customer1Revenues = salesRep1.SalesRepPartyRevenuesWhereSalesRep;
            salesRep1Customer1Revenues.Filter.AddEquals(SalesRepPartyRevenues.Meta.Party, customer1);
            var salesRep1Customer1Revenue = salesRep1Customer1Revenues.First;

            var salesRep2Customer1Revenues = salesRep2.SalesRepPartyRevenuesWhereSalesRep;
            salesRep2Customer1Revenues.Filter.AddEquals(SalesRepPartyRevenues.Meta.Party, customer1);
            var salesRep2Customer1Revenue = salesRep2Customer1Revenues.First;

            var salesRep1Customer1ProductCategoryRevenues = salesRep1.SalesRepPartyProductCategoryRevenuesWhereSalesRep;
            Assert.AreEqual(2, salesRep1Customer1ProductCategoryRevenues.Count);

            salesRep1Customer1ProductCategoryRevenues.Filter.AddEquals(SalesRepPartyProductCategoryRevenues.Meta.ProductCategory, cat1);
            salesRep1Customer1ProductCategoryRevenues.Filter.AddEquals(SalesRepPartyProductCategoryRevenues.Meta.Party, customer1);
            var salesRep1Customer1Cat1Revenue = salesRep1Customer1ProductCategoryRevenues.First;

            salesRep1Customer1ProductCategoryRevenues = salesRep1.SalesRepPartyProductCategoryRevenuesWhereSalesRep;
            salesRep1Customer1ProductCategoryRevenues.Filter.AddEquals(SalesRepPartyProductCategoryRevenues.Meta.ProductCategory, catMain);
            salesRep1Customer1ProductCategoryRevenues.Filter.AddEquals(SalesRepPartyProductCategoryRevenues.Meta.Party, customer1);
            var salesRep1Customer1CatMainRevenue = salesRep1Customer1ProductCategoryRevenues.First;

            var salesRep2Customer1ProductCategoryRevenues = salesRep2.SalesRepPartyProductCategoryRevenuesWhereSalesRep;
            Assert.AreEqual(2, salesRep2Customer1ProductCategoryRevenues.Count);

            salesRep2Customer1ProductCategoryRevenues.Filter.AddEquals(SalesRepPartyProductCategoryRevenues.Meta.ProductCategory, cat2);
            salesRep2Customer1ProductCategoryRevenues.Filter.AddEquals(SalesRepPartyProductCategoryRevenues.Meta.Party, customer1);
            var salesRep2Customer1Cat2Revenue = salesRep2Customer1ProductCategoryRevenues.First;

            salesRep2Customer1ProductCategoryRevenues = salesRep2.SalesRepPartyProductCategoryRevenuesWhereSalesRep;
            salesRep2Customer1ProductCategoryRevenues.Filter.AddEquals(SalesRepPartyProductCategoryRevenues.Meta.Party, customer1);
            salesRep2Customer1ProductCategoryRevenues.Filter.AddEquals(SalesRepPartyProductCategoryRevenues.Meta.ProductCategory, catMain);
            var salesRep2Customer1CatMainRevenue = salesRep2Customer1ProductCategoryRevenues.First;

            var salesRep1ProductCategoryRevenues = salesRep1.SalesRepProductCategoryRevenuesWhereSalesRep;
            Assert.AreEqual(2, salesRep1ProductCategoryRevenues.Count);

            salesRep1ProductCategoryRevenues.Filter.AddEquals(SalesRepProductCategoryRevenues.Meta.ProductCategory, cat1);
            var salesRep1Cat1Revenue = salesRep1ProductCategoryRevenues.First;

            salesRep1ProductCategoryRevenues = salesRep1.SalesRepProductCategoryRevenuesWhereSalesRep;
            salesRep1ProductCategoryRevenues.Filter.AddEquals(SalesRepProductCategoryRevenues.Meta.ProductCategory, catMain);
            var salesRep1CatMainRevenue = salesRep1ProductCategoryRevenues.First;

            var salesRep2ProductCategoryRevenues = salesRep2.SalesRepProductCategoryRevenuesWhereSalesRep;
            Assert.AreEqual(2, salesRep2ProductCategoryRevenues.Count);

            salesRep2ProductCategoryRevenues.Filter.AddEquals(SalesRepProductCategoryRevenues.Meta.ProductCategory, cat2);
            var salesRep2Cat2Revenue = salesRep2ProductCategoryRevenues.First;

            salesRep2ProductCategoryRevenues = salesRep2.SalesRepProductCategoryRevenuesWhereSalesRep;
            salesRep2ProductCategoryRevenues.Filter.AddEquals(SalesRepProductCategoryRevenues.Meta.ProductCategory, catMain);
            var salesRep2CatMainRevenue = salesRep2ProductCategoryRevenues.First;

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(140, internalOrganisationRevenue.Revenue);
            Assert.AreEqual(140, storeRevenue.Revenue);
            Assert.AreEqual(140, salesChannelRevenue.Revenue);
            Assert.AreEqual(90, salesRep1Revenue.Revenue);
            Assert.AreEqual(50, salesRep2Revenue.Revenue);
            Assert.AreEqual(90, salesRep1Customer1Revenue.Revenue);
            Assert.AreEqual(50, salesRep2Customer1Revenue.Revenue);
            Assert.AreEqual(90, good1Revenue.Revenue);
            Assert.AreEqual(50, good2Revenue.Revenue);
            Assert.AreEqual(90, cat1Revenue.Revenue);
            Assert.AreEqual(50, cat2Revenue.Revenue);
            Assert.AreEqual(140, catMainRevenue.Revenue);
            Assert.AreEqual(90, customer1Cat1Revenue.Revenue);
            Assert.AreEqual(50, customer1Cat2Revenue.Revenue);
            Assert.AreEqual(140, customer1CatMainRevenue.Revenue);
            Assert.AreEqual(90, salesRep1Cat1Revenue.Revenue);
            Assert.AreEqual(90, salesRep1CatMainRevenue.Revenue);
            Assert.AreEqual(50, salesRep2Cat2Revenue.Revenue);
            Assert.AreEqual(50, salesRep2CatMainRevenue.Revenue);
            Assert.AreEqual(90, salesRep1Customer1Cat1Revenue.Revenue);
            Assert.AreEqual(90, salesRep1Customer1CatMainRevenue.Revenue);
            Assert.AreEqual(50, salesRep2Customer1Cat2Revenue.Revenue);
            Assert.AreEqual(50, salesRep2Customer1CatMainRevenue.Revenue);
            Assert.AreEqual(140, customer1Revenue.Revenue);
            Assert.AreEqual(90, customer1Good1Revenue.Revenue);
            Assert.AreEqual(50, customer1Good2Revenue.Revenue);

            var invoice2 = new SalesInvoiceBuilder(this.DatabaseSession)
                .WithInvoiceDate(DateTime.UtcNow)
                .WithInvoiceNumber("1")
                .WithBillToCustomer(customer2)
                .WithBillToContactMechanism(contactMechanism)
                .WithSalesChannel(new SalesChannels(this.DatabaseSession).WebChannel)
                .WithSalesInvoiceType(new SalesInvoiceTypes(this.DatabaseSession).SalesInvoice)
                .Build();

            new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(invoice2.BillToCustomer).WithInternalOrganisation(invoice2.BilledFromInternalOrganisation).Build();

            var item4 = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantity(1).WithActualUnitPrice(15).WithSalesInvoiceItemType(productItem).Build();
            invoice2.AddSalesInvoiceItem(item4);

            this.DatabaseSession.Derive(true);

            var item5 = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good2).WithQuantity(1).WithActualUnitPrice(10).WithSalesInvoiceItemType(productItem).Build();
            invoice2.AddSalesInvoiceItem(item5);

            this.DatabaseSession.Derive(true);

            var customer2Revenue = customer2.PartyRevenuesWhereParty[0];

            var customer2ProductRevenues = customer2.PartyProductRevenuesWhereParty;
            Assert.AreEqual(2, customer2ProductRevenues.Count);

            customer2ProductRevenues.Filter.AddEquals(PartyProductRevenues.Meta.Product, good1);
            var customer2Good1Revenue = customer2ProductRevenues.First;

            customer2ProductRevenues = customer2.PartyProductRevenuesWhereParty;
            customer2ProductRevenues.Filter.AddEquals(PartyProductRevenues.Meta.Product, good2);
            var customer2Good2Revenue = customer2ProductRevenues.First;

            var customer2ProductCategoryRevenues = customer2.PartyProductCategoryRevenuesWhereParty;
            Assert.AreEqual(3, customer2ProductCategoryRevenues.Count);

            customer2ProductCategoryRevenues.Filter.AddEquals(PartyProductCategoryRevenues.Meta.ProductCategory, cat1);
            var customer2Cat1Revenue = customer2ProductCategoryRevenues.First;

            customer2ProductCategoryRevenues = customer2.PartyProductCategoryRevenuesWhereParty;
            customer2ProductCategoryRevenues.Filter.AddEquals(PartyProductCategoryRevenues.Meta.ProductCategory, cat2);
            var customer2Cat2Revenue = customer2ProductCategoryRevenues.First;

            customer2ProductCategoryRevenues = customer2.PartyProductCategoryRevenuesWhereParty;
            customer2ProductCategoryRevenues.Filter.AddEquals(PartyProductCategoryRevenues.Meta.ProductCategory, catMain);
            var customer2CatMainRevenue = customer2ProductCategoryRevenues.First;

            var salesRep1Customer2Revenues = salesRep1.SalesRepPartyRevenuesWhereSalesRep;
            salesRep1Customer2Revenues.Filter.AddEquals(SalesRepPartyRevenues.Meta.Party, customer2);
            var salesRep1Customer2Revenue = salesRep1Customer2Revenues.First;

            var salesRep2Customer2Revenues = salesRep2.SalesRepPartyRevenuesWhereSalesRep;
            salesRep2Customer2Revenues.Filter.AddEquals(SalesRepPartyRevenues.Meta.Party, customer2);
            var salesRep2Customer2Revenue = salesRep2Customer2Revenues.First;

            var salesRep1Customer2ProductCategoryRevenues = salesRep1.SalesRepPartyProductCategoryRevenuesWhereSalesRep;
            salesRep1Customer2ProductCategoryRevenues.Filter.AddEquals(SalesRepPartyProductCategoryRevenues.Meta.Party, customer2);
            Assert.AreEqual(2, salesRep1Customer2ProductCategoryRevenues.Count);

            salesRep1Customer2ProductCategoryRevenues.Filter.AddEquals(SalesRepPartyProductCategoryRevenues.Meta.ProductCategory, cat1);
            salesRep1Customer2ProductCategoryRevenues.Filter.AddEquals(SalesRepPartyProductCategoryRevenues.Meta.Party, customer2);
            var salesRep1Customer2Cat1Revenue = salesRep1Customer2ProductCategoryRevenues.First;

            salesRep1Customer2ProductCategoryRevenues = salesRep1.SalesRepPartyProductCategoryRevenuesWhereSalesRep;
            salesRep1Customer2ProductCategoryRevenues.Filter.AddEquals(SalesRepPartyProductCategoryRevenues.Meta.ProductCategory, catMain);
            salesRep1Customer2ProductCategoryRevenues.Filter.AddEquals(SalesRepPartyProductCategoryRevenues.Meta.Party, customer2);
            var salesRep1Customer2CatMainRevenue = salesRep1Customer2ProductCategoryRevenues.First;

            var salesRep2Customer2ProductCategoryRevenues = salesRep2.SalesRepPartyProductCategoryRevenuesWhereSalesRep;
            salesRep2Customer2ProductCategoryRevenues.Filter.AddEquals(SalesRepPartyProductCategoryRevenues.Meta.Party, customer2);
            Assert.AreEqual(2, salesRep2Customer2ProductCategoryRevenues.Count);

            salesRep2Customer2ProductCategoryRevenues.Filter.AddEquals(SalesRepPartyProductCategoryRevenues.Meta.ProductCategory, cat2);
            salesRep2Customer2ProductCategoryRevenues.Filter.AddEquals(SalesRepPartyProductCategoryRevenues.Meta.Party, customer2);
            var salesRep2Customer2Cat2Revenue = salesRep2Customer2ProductCategoryRevenues.First;

            salesRep2Customer2ProductCategoryRevenues = salesRep2.SalesRepPartyProductCategoryRevenuesWhereSalesRep;
            salesRep2Customer2ProductCategoryRevenues.Filter.AddEquals(SalesRepPartyProductCategoryRevenues.Meta.Party, customer2);
            salesRep2Customer2ProductCategoryRevenues.Filter.AddEquals(SalesRepPartyProductCategoryRevenues.Meta.ProductCategory, catMain);
            var salesRep2Customer2CatMainRevenue = salesRep2Customer2ProductCategoryRevenues.First;

            Assert.AreEqual(165, internalOrganisationRevenue.Revenue);
            Assert.AreEqual(165, storeRevenue.Revenue);
            Assert.AreEqual(165, salesChannelRevenue.Revenue);
            Assert.AreEqual(105, salesRep1Revenue.Revenue);
            Assert.AreEqual(60, salesRep2Revenue.Revenue);
            Assert.AreEqual(15, salesRep1Customer2Revenue.Revenue);
            Assert.AreEqual(10, salesRep2Customer2Revenue.Revenue);
            Assert.AreEqual(105, cat1Revenue.Revenue);
            Assert.AreEqual(60, cat2Revenue.Revenue);
            Assert.AreEqual(165, catMainRevenue.Revenue);
            Assert.AreEqual(15, customer2Cat1Revenue.Revenue);
            Assert.AreEqual(10, customer2Cat2Revenue.Revenue);
            Assert.AreEqual(25, customer2CatMainRevenue.Revenue);
            Assert.AreEqual(105, salesRep1Cat1Revenue.Revenue);
            Assert.AreEqual(105, salesRep1CatMainRevenue.Revenue);
            Assert.AreEqual(60, salesRep2Cat2Revenue.Revenue);
            Assert.AreEqual(60, salesRep2CatMainRevenue.Revenue);
            Assert.AreEqual(15, salesRep1Customer2Cat1Revenue.Revenue);
            Assert.AreEqual(15, salesRep1Customer2CatMainRevenue.Revenue);
            Assert.AreEqual(10, salesRep2Customer2Cat2Revenue.Revenue);
            Assert.AreEqual(10, salesRep2Customer2CatMainRevenue.Revenue);
            Assert.AreEqual(105, good1Revenue.Revenue);
            Assert.AreEqual(60, good2Revenue.Revenue);
            Assert.AreEqual(25, customer2Revenue.Revenue);
            Assert.AreEqual(15, customer2Good1Revenue.Revenue);
            Assert.AreEqual(10, customer2Good2Revenue.Revenue);
        }
Ejemplo n.º 30
0
        public void GivenInvoiceItemWithoutVatRegime_WhenDeriving_ThenItemDerivedVatRateIsFromInvoiceVatRegime()
        {
            this.InstantiateObjects(this.DatabaseSession);

            var vatRate0 = new VatRates(this.DatabaseSession).FindBy(VatRates.Meta.Rate, 0);

            var salesInvoice = new SalesInvoiceBuilder(this.DatabaseSession)
                .WithBilledFromInternalOrganisation(this.internalOrganisation)
                .WithBillToCustomer(this.billToCustomer)
                .WithBillToContactMechanism(this.billToContactMechanismMechelen)
                .WithVatRegime(new VatRegimes(this.DatabaseSession).Export)
                .Build();

            var invoiceItem = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(this.good).WithSalesInvoiceItemType(new SalesInvoiceItemTypes(this.DatabaseSession).ProductItem).WithQuantity(1).Build();
            salesInvoice.AddSalesInvoiceItem(invoiceItem);

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(salesInvoice.VatRegime, invoiceItem.VatRegime);
            Assert.AreEqual(vatRate0, invoiceItem.DerivedVatRate);
        }
Ejemplo n.º 31
0
        public void GivenSalesInvoiceWithShippingAndHandlingPercentage_WhenDeriving_ThenSalesInvoiceTotalsMustIncludeShippingAndHandlingAmount()
        {
            var euro = new Currencies(this.DatabaseSession).FindBy(Currencies.Meta.IsoCode, "EUR");
            var vatRate21 = new VatRateBuilder(this.DatabaseSession).WithRate(21).Build();
            var adjustment = new ShippingAndHandlingChargeBuilder(this.DatabaseSession).WithPercentage(5).WithVatRate(vatRate21).Build();
            var contactMechanism = new PostalAddressBuilder(this.DatabaseSession)
                .WithAddress1("Haverwerf 15")
                .WithPostalBoundary(new PostalBoundaryBuilder(this.DatabaseSession)
                                        .WithLocality("Mechelen")
                                        .WithCountry(new Countries(this.DatabaseSession).FindBy(Countries.Meta.IsoCode, "BE"))
                                        .Build())

                .Build();

            var good = new GoodBuilder(this.DatabaseSession)
                .WithSku("10101")
                .WithVatRate(vatRate21)
                .WithName("good")
                .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .Build();

            var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation");
            internalOrganisation.PreferredCurrency = euro;

            var invoice = new SalesInvoiceBuilder(this.DatabaseSession)
                .WithInvoiceNumber("1")
                .WithBillToCustomer(new OrganisationBuilder(this.DatabaseSession).WithName("customer").Build())
                .WithBillToContactMechanism(contactMechanism)
                .WithSalesInvoiceType(new SalesInvoiceTypes(this.DatabaseSession).SalesInvoice)
                .WithShippingAndHandlingCharge(adjustment)
                .Build();

            new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(invoice.BillToCustomer).WithInternalOrganisation(Singleton.Instance(this.DatabaseSession).DefaultInternalOrganisation).Build();

            var item1 = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good).WithQuantity(3).WithActualUnitPrice(15).WithSalesInvoiceItemType(new SalesInvoiceItemTypes(this.DatabaseSession).ProductItem).Build();
            invoice.AddSalesInvoiceItem(item1);

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(45, invoice.TotalBasePrice);
            Assert.AreEqual(0, invoice.TotalDiscount);
            Assert.AreEqual(0, invoice.TotalSurcharge);
            Assert.AreEqual(2.25, invoice.TotalShippingAndHandling);
            Assert.AreEqual(0, invoice.TotalFee);
            Assert.AreEqual(47.25, invoice.TotalExVat);
            Assert.AreEqual(9.92, invoice.TotalVat);
            Assert.AreEqual(57.17, invoice.TotalIncVat);
        }
Ejemplo n.º 32
0
        public void GivenSalesOrderForCustomerExceedingCreditLimit_WhenOrderIsConfirmed_ThenOrderRequestsApproval()
        {
            var productItem = new SalesInvoiceItemTypes(this.DatabaseSession).ProductItem;
            var contactMechanism = new ContactMechanisms(this.DatabaseSession).Extent().First;

            var assessable = new VatRegimes(this.DatabaseSession).Assessable;
            var vatRate0 = new VatRateBuilder(this.DatabaseSession).WithRate(0).Build();
            assessable.VatRate = vatRate0;

            var good = new GoodBuilder(this.DatabaseSession)
                .WithSku("10101")
                .WithVatRate(vatRate0)
                .WithName("good1")
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized)
                .Build();

            var inventoryItem = new NonSerializedInventoryItemBuilder(this.DatabaseSession).WithGood(good).Build();
            inventoryItem.AddInventoryItemVariance(new InventoryItemVarianceBuilder(this.DatabaseSession).WithQuantity(100).WithReason(new VarianceReasons(this.DatabaseSession).Unknown).Build());

            this.DatabaseSession.Derive(true);

            var mechelen = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build();
            var mechelenAddress = new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build();
            var shipToMechelen = new PartyContactMechanismBuilder(this.DatabaseSession)
                .WithContactMechanism(mechelenAddress)
                .WithContactPurpose(new ContactMechanismPurposes(this.DatabaseSession).ShippingAddress)
                .WithUseAsDefault(true)
                .Build();

            var customer = new PersonBuilder(this.DatabaseSession).WithLastName("customer").WithPartyContactMechanism(shipToMechelen).Build();

            new CustomerRelationshipBuilder(this.DatabaseSession)
                .WithCustomer(customer)
                .WithInternalOrganisation(Singleton.Instance(this.DatabaseSession).DefaultInternalOrganisation)
                .WithCreditLimit(100M)
                .Build();

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

            var invoice = new SalesInvoiceBuilder(this.DatabaseSession)
                .WithSalesInvoiceType(new SalesInvoiceTypes(this.DatabaseSession).SalesInvoice)
                .WithBillToCustomer(customer)
                .WithBillToContactMechanism(contactMechanism)
                .WithInvoiceDate(DateTime.UtcNow.AddYears(-1))
                .Build();

            var invoiceItem = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good).WithQuantity(10).WithActualUnitPrice(11).WithSalesInvoiceItemType(productItem).Build();
            invoice.AddSalesInvoiceItem(invoiceItem);

            this.DatabaseSession.Derive(true);

            var order = new SalesOrderBuilder(this.DatabaseSession)
                .WithBillToCustomer(customer)
                .WithShipToCustomer(customer)
                .WithVatRegime(assessable)
                .WithShipToAddress(new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build())
                .Build();

            var item = new SalesOrderItemBuilder(this.DatabaseSession)
                .WithProduct(good)
                .WithQuantityOrdered(10)
                .WithActualUnitPrice(5)
                .Build();

            order.AddSalesOrderItem(item);

            this.DatabaseSession.Derive(true);

            order.Confirm();

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(new SalesOrderObjectStates(this.DatabaseSession).RequestsApproval, order.CurrentObjectState);
            Assert.AreEqual(0, item.QuantityReserved);
            Assert.AreEqual(0, item.QuantityPendingShipment);
            Assert.AreEqual(0, item.QuantityRequestsShipping);
            Assert.AreEqual(0, item.QuantityShortFalled);

            order.Approve();

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(new SalesOrderObjectStates(this.DatabaseSession).InProcess, order.CurrentObjectState);
            Assert.AreEqual(10, item.QuantityReserved);
            Assert.AreEqual(10, item.QuantityPendingShipment);
            Assert.AreEqual(0, item.QuantityRequestsShipping);
            Assert.AreEqual(0, item.QuantityShortFalled);
        }
Ejemplo n.º 33
0
        public void GivenInvoiceItemForGood1WithActualPrice_WhenDerivingPrices_ThenUseActualPrice()
        {
            this.InstantiateObjects(this.DatabaseSession);

            var item1 = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(this.good).WithSalesInvoiceItemType(new SalesInvoiceItemTypes(this.DatabaseSession).ProductItem).WithQuantity(3).WithActualUnitPrice(15).Build();
            this.invoice.AddSalesInvoiceItem(item1);

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(10, item1.UnitBasePrice);
            Assert.AreEqual(0, item1.UnitDiscount);
            Assert.AreEqual(0, item1.UnitSurcharge);
            Assert.AreEqual(15, item1.CalculatedUnitPrice);
            Assert.AreEqual(3.15, item1.UnitVat);
            Assert.AreEqual(45, item1.TotalBasePrice);
            Assert.AreEqual(0, item1.TotalDiscount);
            Assert.AreEqual(0, item1.TotalSurcharge);
            Assert.AreEqual(45, item1.TotalExVat);
            Assert.AreEqual(9.45, item1.TotalVat);
            Assert.AreEqual(54.45, item1.TotalIncVat);
            Assert.AreEqual(7, 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);

            Assert.AreEqual(45, this.invoice.TotalBasePrice);
            Assert.AreEqual(0, this.invoice.TotalDiscount);
            Assert.AreEqual(0, this.invoice.TotalSurcharge);
            Assert.AreEqual(45, this.invoice.TotalExVat);
            Assert.AreEqual(9.45, this.invoice.TotalVat);
            Assert.AreEqual(54.45, this.invoice.TotalIncVat);
            Assert.AreEqual(7, this.invoice.TotalPurchasePrice);
            Assert.AreEqual(15, this.invoice.TotalListPrice);
        }
Ejemplo n.º 34
0
        public void AppsInvoiceThis(IDerivation derivation)
        {
            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;
                    var salesOrderItem = orderShipment.OrderItem as SalesOrderItem;

                    if (!invoiceByOrder.TryGetValue(salesOrder, out var salesInvoice))
                    {
                        salesInvoice = new SalesInvoiceBuilder(this.Strategy.Session)
                                       .WithStore(salesOrder.Store)
                                       .WithBilledFrom(salesOrder.TakenBy)
                                       .WithBilledFromContactMechanism(salesOrder.TakenByContactMechanism)
                                       .WithBilledFromContactPerson(salesOrder.TakenByContactPerson)
                                       .WithBillToCustomer(salesOrder.BillToCustomer)
                                       .WithBillToContactMechanism(salesOrder.BillToContactMechanism)
                                       .WithBillToContactPerson(salesOrder.BillToContactPerson)
                                       .WithBillToEndCustomer(salesOrder.BillToEndCustomer)
                                       .WithBillToEndCustomerContactMechanism(salesOrder.BillToEndCustomerContactMechanism)
                                       .WithBillToEndCustomerContactPerson(salesOrder.BillToEndCustomerContactPerson)
                                       .WithShipToCustomer(salesOrder.ShipToCustomer)
                                       .WithShipToAddress(salesOrder.ShipToAddress)
                                       .WithShipToContactPerson(salesOrder.ShipToContactPerson)
                                       .WithShipToEndCustomer(salesOrder.ShipToEndCustomer)
                                       .WithShipToEndCustomerAddress(salesOrder.ShipToEndCustomerAddress)
                                       .WithShipToEndCustomerContactPerson(salesOrder.ShipToEndCustomerContactPerson)
                                       .WithInvoiceDate(DateTime.UtcNow)
                                       .WithSalesChannel(salesOrder.SalesChannel)
                                       .WithSalesInvoiceType(new SalesInvoiceTypes(this.Strategy.Session).SalesInvoice)
                                       .WithVatRegime(salesOrder.VatRegime)
                                       .WithDiscountAdjustment(salesOrder.DiscountAdjustment)
                                       .WithSurchargeAdjustment(salesOrder.SurchargeAdjustment)
                                       .WithShippingAndHandlingCharge(salesOrder.ShippingAndHandlingCharge)
                                       .WithFee(salesOrder.Fee)
                                       .WithCustomerReference(salesOrder.CustomerReference)
                                       .WithPaymentMethod(this.PaymentMethod)
                                       .Build();

                        invoiceByOrder.Add(salesOrder, salesInvoice);

                        if (!costsInvoiced)
                        {
                            var costs = this.AppsOnDeriveShippingAndHandlingCharges(derivation);
                            if (costs > 0)
                            {
                                salesInvoice.ShippingAndHandlingCharge = 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.ActualUnitPrice) - amountAlreadyInvoiced;

                    if (leftToInvoice > 0)
                    {
                        if (salesOrderItem != null)
                        {
                            var invoiceItem = new SalesInvoiceItemBuilder(this.Strategy.Session)
                                              .WithInvoiceItemType(new InvoiceItemTypes(this.Strategy.Session).ProductItem)
                                              .WithProduct(salesOrderItem.Product)
                                              .WithQuantity(orderShipment.Quantity)
                                              .Build();

                            salesInvoice.AddSalesInvoiceItem(invoiceItem);

                            new ShipmentItemBillingBuilder(this.strategy.Session)
                            .WithQuantity(shipmentItem.Quantity)
                            .WithAmount(leftToInvoice)
                            .WithShipmentItem(shipmentItem)
                            .WithInvoiceItem(invoiceItem)
                            .Build();
                        }
                    }
                }
            }
        }
Ejemplo n.º 35
0
        public void GivenInvoiceItemForGood1_WhenDerivingPrices_ThenUsePriceComponentsForGood1()
        {
            this.InstantiateObjects(this.DatabaseSession);

            const decimal quantity = 3;
            var item1 = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(this.good).WithSalesInvoiceItemType(new SalesInvoiceItemTypes(this.DatabaseSession).ProductItem).WithQuantity(quantity).Build();
            this.invoice.AddSalesInvoiceItem(item1);

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(this.currentGood1BasePrice.Price, item1.UnitBasePrice);
            Assert.AreEqual(0, item1.UnitDiscount);
            Assert.AreEqual(0, item1.UnitSurcharge);
            Assert.AreEqual(this.currentGood1BasePrice.Price, item1.CalculatedUnitPrice);
            Assert.AreEqual(decimal.Round((item1.CalculatedUnitPrice * this.vatRate21.Rate) / 100, 2), item1.UnitVat);
            Assert.AreEqual(this.goodPurchasePrice.Price, item1.UnitPurchasePrice);

            Assert.AreEqual(this.currentGood1BasePrice.Price * quantity, item1.TotalBasePrice);
            Assert.AreEqual(0, item1.TotalDiscount);
            Assert.AreEqual(0, item1.TotalSurcharge);
            Assert.AreEqual(this.currentGood1BasePrice.Price * quantity, item1.TotalExVat);
            Assert.AreEqual(decimal.Round((item1.CalculatedUnitPrice * this.vatRate21.Rate) / 100, 2) * quantity, item1.TotalVat);

            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);

            Assert.AreEqual(this.currentGood1BasePrice.Price * quantity, this.invoice.TotalBasePrice);
            Assert.AreEqual(0, this.invoice.TotalDiscount);
            Assert.AreEqual(0, this.invoice.TotalSurcharge);
            Assert.AreEqual(this.currentGood1BasePrice.Price * quantity, this.invoice.TotalExVat);
            Assert.AreEqual(decimal.Round((item1.CalculatedUnitPrice * this.vatRate21.Rate) / 100, 2) * quantity, this.invoice.TotalVat);
            Assert.AreEqual(item1.UnitPurchasePrice, this.invoice.TotalPurchasePrice);
        }
Ejemplo n.º 36
0
        public void DeriveRevenues()
        {
            var productItem = new SalesInvoiceItemTypes(this.DatabaseSession).ProductItem;
            var contactMechanism = new ContactMechanisms(this.DatabaseSession).Extent().First;

            var customer1 = new OrganisationBuilder(this.DatabaseSession).WithName("customer1").Build();
            var customer2 = new OrganisationBuilder(this.DatabaseSession).WithName("customer2").Build();
            var salesRep1 = new PersonBuilder(this.DatabaseSession).WithLastName("salesRep1").Build();
            var salesRep2 = new PersonBuilder(this.DatabaseSession).WithLastName("salesRep2").Build();
            var catMain = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("main cat").Build();
            var cat1 = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("cat for good1").WithParent(catMain).Build();
            var cat2 = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("cat for good2").WithParent(catMain).Build();

            new SalesRepRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer1).WithProductCategory(cat1).WithSalesRepresentative(salesRep1).Build();
            new SalesRepRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer1).WithProductCategory(cat2).WithSalesRepresentative(salesRep2).Build();

            this.DatabaseSession.Derive(true);

            new SalesRepRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer2).WithProductCategory(cat1).WithSalesRepresentative(salesRep1).Build();
            new SalesRepRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer2).WithProductCategory(cat2).WithSalesRepresentative(salesRep2).Build();

            this.DatabaseSession.Derive(true);

            var euro = new Currencies(this.DatabaseSession).FindBy(Currencies.Meta.IsoCode, "EUR");
            var vatRate21 = new VatRateBuilder(this.DatabaseSession).WithRate(21).Build();

            var good1 = new GoodBuilder(this.DatabaseSession)
                .WithSku("10101")
                .WithVatRate(vatRate21)
                .WithName("good1")
                .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .WithPrimaryProductCategory(cat1)
                .Build();

            var good2 = new GoodBuilder(this.DatabaseSession)
                .WithSku("10102")
                .WithVatRate(vatRate21)
                .WithName("good2")
                .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .WithPrimaryProductCategory(cat2)
                .Build();

            var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation");
            internalOrganisation.PreferredCurrency = euro;

            new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer1).WithInternalOrganisation(internalOrganisation).Build();
            new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer2).WithInternalOrganisation(internalOrganisation).Build();

            this.DatabaseSession.Derive(true);

            var invoice1 = new SalesInvoiceBuilder(this.DatabaseSession)
                .WithInvoiceDate(DateTime.UtcNow)
                .WithInvoiceNumber("1")
                .WithBillToCustomer(customer1)
                .WithBillToContactMechanism(contactMechanism)
                .WithSalesInvoiceType(new SalesInvoiceTypes(this.DatabaseSession).SalesInvoice)
                .Build();

            var item1 = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantity(3).WithActualUnitPrice(15).WithSalesInvoiceItemType(productItem).Build();
            invoice1.AddSalesInvoiceItem(item1);

            var item2 = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantity(3).WithActualUnitPrice(15).WithSalesInvoiceItemType(productItem).Build();
            invoice1.AddSalesInvoiceItem(item2);

            var item3 = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good2).WithQuantity(5).WithActualUnitPrice(10).WithSalesInvoiceItemType(productItem).Build();
            invoice1.AddSalesInvoiceItem(item3);

            this.DatabaseSession.Derive(true);

            Singleton.Instance(this.DatabaseSession).DeriveRevenues();

            var customer1ProductRevenues = customer1.PartyProductRevenuesWhereParty;
            Assert.AreEqual(2, customer1ProductRevenues.Count);

            customer1ProductRevenues = customer1.PartyProductRevenuesWhereParty;
            customer1ProductRevenues.Filter.AddEquals(PartyProductRevenues.Meta.Product, good1);
            var customer1Good1Revenue = customer1ProductRevenues.First;

            customer1ProductRevenues = customer1.PartyProductRevenuesWhereParty;
            customer1ProductRevenues.Filter.AddEquals(PartyProductRevenues.Meta.Product, good2);
            var customer1Good2Revenue = customer1ProductRevenues.First;

            Assert.AreEqual(90, customer1Good1Revenue.Revenue);
            Assert.AreEqual(6, customer1Good1Revenue.Quantity);
            Assert.AreEqual(50, customer1Good2Revenue.Revenue);
            Assert.AreEqual(5, customer1Good2Revenue.Quantity);

            var invoice2 = new SalesInvoiceBuilder(this.DatabaseSession)
                .WithInvoiceDate(DateTime.UtcNow)
                .WithInvoiceNumber("1")
                .WithBillToCustomer(customer2)
                .WithBillToContactMechanism(contactMechanism)
                .WithSalesInvoiceType(new SalesInvoiceTypes(this.DatabaseSession).SalesInvoice)
                .Build();

            var item4 = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantity(1).WithActualUnitPrice(15).WithSalesInvoiceItemType(productItem).Build();
            invoice2.AddSalesInvoiceItem(item4);

            this.DatabaseSession.Derive(true);

            var item5 = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good2).WithQuantity(1).WithActualUnitPrice(10).WithSalesInvoiceItemType(productItem).Build();
            invoice2.AddSalesInvoiceItem(item5);

            this.DatabaseSession.Derive(true);

            Singleton.Instance(this.DatabaseSession).DeriveRevenues();

            var customer2ProductRevenues = customer2.PartyProductRevenuesWhereParty;
            Assert.AreEqual(2, customer2ProductRevenues.Count);

            customer2ProductRevenues.Filter.AddEquals(PartyProductRevenues.Meta.Product, good1);
            var customer2Good1Revenue = customer2ProductRevenues.First;

            customer2ProductRevenues = customer2.PartyProductRevenuesWhereParty;
            customer2ProductRevenues.Filter.AddEquals(PartyProductRevenues.Meta.Product, good2);
            var customer2Good2Revenue = customer2ProductRevenues.First;

            Assert.AreEqual(15, customer2Good1Revenue.Revenue);
            Assert.AreEqual(1, customer2Good1Revenue.Quantity);
            Assert.AreEqual(10, customer2Good2Revenue.Revenue);
            Assert.AreEqual(1, customer2Good2Revenue.Quantity);
        }
Ejemplo n.º 37
0
        public void GivenInvoiceItemWithSurchargePercentageForProductCatergory_WhenDeriving_ThenUseSurchargeComponentsForProductCatergory()
        {
            const decimal quantity = 3;
            const decimal percentage = 5;

            var category = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("gizmo").Build();
            new SurchargeComponentBuilder(this.DatabaseSession)
                .WithSpecifiedFor(this.internalOrganisation)
                .WithDescription("discount good for product category")
                .WithProductCategory(category)
                .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.good.AddProductCategory(category);

            this.DatabaseSession.Derive(true);

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

            this.DatabaseSession.Derive(true);

            var amount = decimal.Round((this.currentGood1BasePrice.Price * percentage) / 100, 2);
            Assert.AreEqual(this.currentGood1BasePrice.Price, item1.UnitBasePrice);
            Assert.AreEqual(0, item1.UnitDiscount);
            Assert.AreEqual(amount, item1.UnitSurcharge);
            Assert.AreEqual(this.currentGood1BasePrice.Price + amount, 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.º 38
0
        public void Execute()
        {
            var singleton   = this.Session.GetSingleton();
            var dutchLocale = new Locales(this.Session).DutchNetherlands;

            singleton.AddAdditionalLocale(dutchLocale);

            var euro = new Currencies(this.Session).FindBy(M.Currency.IsoCode, "EUR");

            var be = new Countries(this.Session).FindBy(M.Country.IsoCode, "BE");
            var us = new Countries(this.Session).FindBy(M.Country.IsoCode, "US");

            var email2 = new EmailAddressBuilder(this.Session)
                         .WithElectronicAddressString("*****@*****.**")
                         .Build();

            var allorsLogo = this.DataPath + @"\www\admin\images\logo.png";

            var allors = Organisations.CreateInternalOrganisation(
                session: this.Session,
                name: "Allors BVBA",
                address: "Kleine Nieuwedijkstraat 4",
                postalCode: "2800",
                locality: "Mechelen",
                country: be,
                phone1CountryCode: "+32",
                phone1: "2 335 2335",
                phone1Purpose: new ContactMechanismPurposes(this.Session).GeneralPhoneNumber,
                phone2CountryCode: string.Empty,
                phone2: string.Empty,
                phone2Purpose: null,
                emailAddress: "*****@*****.**",
                websiteAddress: "www.allors.com",
                taxNumber: "BE 0476967014",
                bankName: "ING",
                facilityName: "Allors warehouse 1",
                bic: "BBRUBEBB",
                iban: "BE89 3200 1467 7685",
                currency: euro,
                logo: allorsLogo,
                storeName: "Allors Store",
                billingProcess: new BillingProcesses(this.Session).BillingForOrderItems,
                outgoingShipmentNumberPrefix: "a-CS",
                salesInvoiceNumberPrefix: "a-SI",
                salesOrderNumberPrefix: "a-SO",
                requestNumberPrefix: "a-RFQ",
                quoteNumberPrefix: "a-Q",
                productNumberPrefix: "A-",
                requestCounterValue: 1,
                quoteCounterValue: 1,
                orderCounterValue: 1,
                invoiceCounterValue: 1);

            var dipu = Organisations.CreateInternalOrganisation(
                session: this.Session,
                name: "Dipu BVBA",
                address: "Kleine Nieuwedijkstraat 2",
                postalCode: "2800",
                locality: "Mechelen",
                country: be,
                phone1CountryCode: "+32",
                phone1: "2 15 49 49 49",
                phone1Purpose: new ContactMechanismPurposes(this.Session).GeneralPhoneNumber,
                phone2CountryCode: string.Empty,
                phone2: string.Empty,
                phone2Purpose: null,
                emailAddress: "*****@*****.**",
                websiteAddress: "www.dipu.com",
                taxNumber: "BE 0445366489",
                bankName: "ING",
                facilityName: "Dipu Facility",
                bic: "BBRUBEBB",
                iban: "BE23 3300 6167 6391",
                currency: euro,
                logo: allorsLogo,
                storeName: "Dipu Store",
                billingProcess: new BillingProcesses(this.Session).BillingForOrderItems,
                outgoingShipmentNumberPrefix: "d-CS",
                salesInvoiceNumberPrefix: "d-SI",
                salesOrderNumberPrefix: "d-SO",
                requestNumberPrefix: "d-RFQ",
                quoteNumberPrefix: "d-Q",
                productNumberPrefix: "D-",
                requestCounterValue: 1,
                quoteCounterValue: 1,
                orderCounterValue: 1,
                invoiceCounterValue: 1);

            singleton.Settings.DefaultFacility = allors.FacilitiesWhereOwner.First;

            this.SetupUser(allors, "*****@*****.**", "first", "allors employee", "letmein");
            this.SetupUser(allors, "*****@*****.**", "second", "allors employee", "letmein");
            this.SetupUser(dipu, "*****@*****.**", "first", "dipu employee", "letmein");

            new FacilityBuilder(this.Session)
            .WithName("Allors warehouse 2")
            .WithFacilityType(new FacilityTypes(this.Session).Warehouse)
            .WithOwner(allors)
            .Build();

            var manufacturer = new OrganisationBuilder(this.Session).WithName("Gizmo inc.").WithIsManufacturer(true).Build();

            var productType = new ProductTypeBuilder(this.Session)
                              .WithName($"Gizmo Serialized")
                              .WithSerialisedItemCharacteristicType(new SerialisedItemCharacteristicTypeBuilder(this.Session)
                                                                    .WithName("Size")
                                                                    .WithLocalisedName(new LocalisedTextBuilder(this.Session).WithText("Afmeting").WithLocale(dutchLocale).Build())
                                                                    .Build())
                              .WithSerialisedItemCharacteristicType(new SerialisedItemCharacteristicTypeBuilder(this.Session)
                                                                    .WithName("Weight")
                                                                    .WithLocalisedName(new LocalisedTextBuilder(this.Session).WithText("Gewicht").WithLocale(dutchLocale).Build())
                                                                    .WithUnitOfMeasure(new UnitsOfMeasure(this.Session).Kilogram)
                                                                    .Build())
                              .Build();

            var vatRate = new VatRateBuilder(this.Session).WithRate(21).Build();

            var brand = new BrandBuilder(this.Session)
                        .WithName("brand1")
                        .WithModel(new ModelBuilder(this.Session).WithName("model1").Build())
                        .Build();

            var finishedGood = new NonUnifiedPartBuilder(this.Session)
                               .WithProductIdentification(new SkuIdentificationBuilder(this.Session)
                                                          .WithIdentification("10101")
                                                          .WithProductIdentificationType(new ProductIdentificationTypes(this.Session).Sku).Build())
                               .WithName("finished good")
                               .WithBrand(brand)
                               .WithModel(brand.Models[0])
                               .WithManufacturedBy(manufacturer)
                               .WithInventoryItemKind(new InventoryItemKinds(this.Session).NonSerialised)
                               .Build();

            var good1 = new NonUnifiedGoodBuilder(this.Session)
                        .WithName("Tiny blue round gizmo")
                        .WithLocalisedName(new LocalisedTextBuilder(this.Session).WithText("Zeer kleine blauwe ronde gizmo").WithLocale(dutchLocale).Build())
                        .WithDescription("Perfect blue with nice curves")
                        .WithLocalisedDescription(new LocalisedTextBuilder(this.Session).WithText("Perfect blauw met mooie rondingen").WithLocale(dutchLocale).Build())
                        .WithVatRate(vatRate)
                        .WithPart(finishedGood)
                        .Build();

            new InventoryItemTransactionBuilder(this.Session).WithPart(finishedGood).WithQuantity(100).WithReason(new InventoryTransactionReasons(this.Session).Unknown).Build();

            var finishedGood2 = new NonUnifiedPartBuilder(this.Session)
                                .WithName("finished good2")
                                .WithInventoryItemKind(new InventoryItemKinds(this.Session).Serialised)
                                .WithProductType(productType)
                                .WithProductIdentification(new SkuIdentificationBuilder(this.Session)
                                                           .WithIdentification("10102")
                                                           .WithProductIdentificationType(new ProductIdentificationTypes(this.Session).Sku).Build())
                                .WithManufacturedBy(manufacturer)
                                .Build();

            var good2 = new NonUnifiedGoodBuilder(this.Session)
                        .WithName("Tiny red round gizmo")
                        .WithLocalisedName(new LocalisedTextBuilder(this.Session).WithText("Zeer kleine rode ronde gizmo").WithLocale(dutchLocale).Build())
                        .WithDescription("Perfect red with nice curves")
                        .WithLocalisedDescription(new LocalisedTextBuilder(this.Session).WithText("Perfect rood met mooie rondingen").WithLocale(dutchLocale).Build())
                        .WithVatRate(vatRate)
                        .WithPart(finishedGood2)
                        .Build();

            var serialisedItem = new SerialisedItemBuilder(this.Session).WithSerialNumber("1").Build();

            finishedGood2.AddSerialisedItem(serialisedItem);

            new SerialisedInventoryItemBuilder(this.Session).WithPart(finishedGood2).WithSerialisedItem(serialisedItem).WithFacility(allors.StoresWhereInternalOrganisation.First.DefaultFacility).Build();

            var finishedGood3 = new NonUnifiedPartBuilder(this.Session)
                                .WithProductIdentification(new SkuIdentificationBuilder(this.Session)
                                                           .WithIdentification("10103")
                                                           .WithProductIdentificationType(new ProductIdentificationTypes(this.Session).Sku).Build())
                                .WithName("finished good3")
                                .WithInventoryItemKind(new InventoryItemKinds(this.Session).NonSerialised)
                                .WithManufacturedBy(manufacturer)
                                .Build();

            var good3 = new NonUnifiedGoodBuilder(this.Session)
                        .WithName("Tiny green round gizmo")
                        .WithLocalisedName(new LocalisedTextBuilder(this.Session).WithText("Zeer kleine groene ronde gizmo").WithLocale(dutchLocale).Build())
                        .WithDescription("Perfect red with nice curves")
                        .WithLocalisedDescription(new LocalisedTextBuilder(this.Session).WithText("Perfect groen met mooie rondingen").WithLocale(dutchLocale).Build())
                        .WithVatRate(vatRate)
                        .WithPart(finishedGood3)
                        .Build();

            var productCategory1 = new ProductCategoryBuilder(this.Session)
                                   .WithInternalOrganisation(allors)
                                   .WithName("Best selling gizmo's")
                                   .WithLocalisedName(new LocalisedTextBuilder(this.Session).WithText("Meest verkochte gizmo's").WithLocale(dutchLocale).Build())
                                   .Build();

            var productCategory2 = new ProductCategoryBuilder(this.Session)
                                   .WithInternalOrganisation(allors)
                                   .WithName("Big Gizmo's")
                                   .WithLocalisedName(new LocalisedTextBuilder(this.Session).WithText("Grote Gizmo's").WithLocale(dutchLocale).Build())
                                   .Build();

            var productCategory3 = new ProductCategoryBuilder(this.Session)
                                   .WithInternalOrganisation(allors)
                                   .WithName("Small gizmo's")
                                   .WithLocalisedName(new LocalisedTextBuilder(this.Session).WithText("Kleine gizmo's").WithLocale(dutchLocale).Build())
                                   .WithProduct(good1)
                                   .WithProduct(good2)
                                   .WithProduct(good3)
                                   .Build();

            new CatalogueBuilder(this.Session)
            .WithInternalOrganisation(allors)
            .WithName("New gizmo's")
            .WithLocalisedName(new LocalisedTextBuilder(this.Session).WithText("Nieuwe gizmo's").WithLocale(dutchLocale).Build())
            .WithDescription("Latest in the world of Gizmo's")
            .WithLocalisedDescription(new LocalisedTextBuilder(this.Session).WithText("Laatste in de wereld van Gizmo's").WithLocale(dutchLocale).Build())
            .WithProductCategory(productCategory1)
            .Build();

            this.Session.Derive();

            for (int i = 0; i < 1; i++)
            {
                var acmePostalAddress = new PostalAddressBuilder(this.Session)
                                        .WithAddress1($"Acme{i} address 1")
                                        .WithPostalBoundary(new PostalBoundaryBuilder(this.Session).WithLocality($"Acme{i} city").WithPostalCode("1111").WithCountry(us).Build())
                                        .Build();

                var acmeBillingAddress = new PartyContactMechanismBuilder(this.Session)
                                         .WithContactMechanism(acmePostalAddress)
                                         .WithContactPurpose(new ContactMechanismPurposes(this.Session).GeneralCorrespondence)
                                         .WithUseAsDefault(true)
                                         .Build();

                var acmeInquiries = new PartyContactMechanismBuilder(this.Session)
                                    .WithContactMechanism(new TelecommunicationsNumberBuilder(this.Session).WithCountryCode("+1").WithContactNumber("111 222 333").Build())
                                    .WithContactPurpose(new ContactMechanismPurposes(this.Session).GeneralPhoneNumber)
                                    .WithContactPurpose(new ContactMechanismPurposes(this.Session).OrderInquiriesPhone)
                                    .WithUseAsDefault(true)
                                    .Build();

                var acme = new OrganisationBuilder(this.Session)
                           .WithName($"Acme{i}")
                           .WithLocale(new Locales(this.Session).EnglishUnitedStates)
                           .WithPartyContactMechanism(acmeBillingAddress)
                           .WithPartyContactMechanism(acmeInquiries)
                           .Build();

                var contact1Email = new PartyContactMechanismBuilder(this.Session)
                                    .WithContactMechanism(new EmailAddressBuilder(this.Session).WithElectronicAddressString($"employee1@acme{i}.com").Build())
                                    .WithContactPurpose(new ContactMechanismPurposes(this.Session).PersonalEmailAddress)
                                    .WithUseAsDefault(true)
                                    .Build();

                var contact2PhoneNumber = new PartyContactMechanismBuilder(this.Session)
                                          .WithContactMechanism(new TelecommunicationsNumberBuilder(this.Session).WithCountryCode("+1").WithAreaCode("123").WithContactNumber("456").Build())
                                          .WithContactPurpose(new ContactMechanismPurposes(this.Session).GeneralPhoneNumber)
                                          .WithUseAsDefault(true)
                                          .Build();

                var contact1 = new PersonBuilder(this.Session)
                               .WithFirstName($"John{i}")
                               .WithLastName($"Doe{i}")
                               .WithGender(new GenderTypes(this.Session).Male)
                               .WithLocale(new Locales(this.Session).EnglishUnitedStates)
                               .WithPartyContactMechanism(contact1Email)
                               .Build();

                var contact2 = new PersonBuilder(this.Session)
                               .WithFirstName($"Jane{i}")
                               .WithLastName($"Doe{i}")
                               .WithGender(new GenderTypes(this.Session).Male)
                               .WithLocale(new Locales(this.Session).EnglishUnitedStates)
                               .WithPartyContactMechanism(contact2PhoneNumber)
                               .Build();

                new CustomerRelationshipBuilder(this.Session)
                .WithCustomer(acme)
                .WithInternalOrganisation(allors)
                .WithFromDate(DateTime.UtcNow)
                .Build();

                new SupplierRelationshipBuilder(this.Session)
                .WithSupplier(acme)
                .WithInternalOrganisation(allors)
                .WithFromDate(DateTime.UtcNow)
                .Build();

                new OrganisationContactRelationshipBuilder(this.Session)
                .WithOrganisation(acme)
                .WithContact(contact1)
                .WithContactKind(new OrganisationContactKinds(this.Session).FindBy(M.OrganisationContactKind.Description, "General contact"))
                .WithFromDate(DateTime.UtcNow)
                .Build();

                new OrganisationContactRelationshipBuilder(this.Session)
                .WithOrganisation(acme)
                .WithContact(contact2)
                .WithContactKind(new OrganisationContactKinds(this.Session).FindBy(M.OrganisationContactKind.Description, "General contact"))
                .WithFromDate(DateTime.UtcNow)
                .Build();

                var administrator = (Person) new UserGroups(this.Session).Administrators.Members.First;

                new FaceToFaceCommunicationBuilder(this.Session)
                .WithDescription($"Meeting {i}")
                .WithSubject($"meeting {i}")
                .WithEventPurpose(new CommunicationEventPurposes(this.Session).Meeting)
                .WithFromParty(contact1)
                .WithToParty(contact2)
                .WithOwner(administrator)
                .WithActualStart(DateTime.UtcNow)
                .Build();

                new EmailCommunicationBuilder(this.Session)
                .WithDescription($"Email {i}")
                .WithSubject($"email {i}")
                .WithFromEmail(email2)
                .WithToEmail(email2)
                .WithEventPurpose(new CommunicationEventPurposes(this.Session).Meeting)
                .WithOwner(administrator)
                .WithActualStart(DateTime.UtcNow)
                .Build();

                new LetterCorrespondenceBuilder(this.Session)
                .WithDescription($"Letter {i}")
                .WithSubject($"letter {i}")
                .WithFromParty(administrator)
                .WithToParty(contact1)
                .WithEventPurpose(new CommunicationEventPurposes(this.Session).Meeting)
                .WithOwner(administrator)
                .WithActualStart(DateTime.UtcNow)
                .Build();

                new PhoneCommunicationBuilder(this.Session)
                .WithDescription($"Phone {i}")
                .WithSubject($"phone {i}")
                .WithFromParty(administrator)
                .WithToParty(contact1)
                .WithEventPurpose(new CommunicationEventPurposes(this.Session).Meeting)
                .WithOwner(administrator)
                .WithActualStart(DateTime.UtcNow)
                .Build();

                var salesOrderItem1 = new SalesOrderItemBuilder(this.Session)
                                      .WithDescription("first item")
                                      .WithProduct(good1)
                                      .WithActualUnitPrice(3000)
                                      .WithQuantityOrdered(1)
                                      .WithMessage(@"line1
line2")
                                      .WithInvoiceItemType(new InvoiceItemTypes(this.Session).ProductItem)
                                      .Build();

                var salesOrderItem2 = new SalesOrderItemBuilder(this.Session)
                                      .WithDescription("second item")
                                      .WithActualUnitPrice(2000)
                                      .WithQuantityOrdered(2)
                                      .WithInvoiceItemType(new InvoiceItemTypes(this.Session).ProductItem)
                                      .Build();

                var salesOrderItem3 = new SalesOrderItemBuilder(this.Session)
                                      .WithDescription("Fee")
                                      .WithActualUnitPrice(100)
                                      .WithQuantityOrdered(1)
                                      .WithInvoiceItemType(new InvoiceItemTypes(this.Session).Fee)
                                      .Build();

                var order = new SalesOrderBuilder(this.Session)
                            .WithTakenBy(allors)
                            .WithBillToCustomer(acme)
                            .WithBillToEndCustomerContactMechanism(acmeBillingAddress.ContactMechanism)
                            .WithSalesOrderItem(salesOrderItem1)
                            .WithSalesOrderItem(salesOrderItem2)
                            .WithSalesOrderItem(salesOrderItem3)
                            .WithCustomerReference("a reference number")
                            .WithDescription("Sale of 1 used Aircraft Towbar")
                            .WithVatRegime(new VatRegimes(this.Session).Assessable)
                            .Build();

                var salesInvoiceItem1 = new SalesInvoiceItemBuilder(this.Session)
                                        .WithDescription("first item")
                                        .WithProduct(good1)
                                        .WithActualUnitPrice(3000)
                                        .WithQuantity(1)
                                        .WithMessage(@"line1
line2")
                                        .WithInvoiceItemType(new InvoiceItemTypes(this.Session).ProductItem)
                                        .Build();

                var salesInvoiceItem2 = new SalesInvoiceItemBuilder(this.Session)
                                        .WithDescription("second item")
                                        .WithActualUnitPrice(2000)
                                        .WithQuantity(2)
                                        .WithInvoiceItemType(new InvoiceItemTypes(this.Session).ProductItem)
                                        .Build();

                var salesInvoiceItem3 = new SalesInvoiceItemBuilder(this.Session)
                                        .WithDescription("Fee")
                                        .WithActualUnitPrice(100)
                                        .WithQuantity(1)
                                        .WithInvoiceItemType(new InvoiceItemTypes(this.Session).Fee)
                                        .Build();

                var salesInvoice = new SalesInvoiceBuilder(this.Session)
                                   .WithBilledFrom(allors)
                                   .WithInvoiceNumber("1")
                                   .WithBillToCustomer(acme)
                                   .WithBillToContactMechanism(acme.PartyContactMechanisms[0].ContactMechanism)
                                   .WithBillToEndCustomerContactMechanism(acmeBillingAddress.ContactMechanism)
                                   .WithSalesInvoiceItem(salesInvoiceItem1)
                                   .WithSalesInvoiceItem(salesInvoiceItem2)
                                   .WithSalesInvoiceItem(salesInvoiceItem3)
                                   .WithCustomerReference("a reference number")
                                   .WithDescription("Sale of 1 used Aircraft Towbar")
                                   .WithSalesInvoiceType(new SalesInvoiceTypes(this.Session).SalesInvoice)
                                   .WithVatRegime(new VatRegimes(this.Session).Assessable)
                                   .Build();

                var purchaseInvoiceItem1 = new PurchaseInvoiceItemBuilder(this.Session)
                                           .WithDescription("first item")
                                           .WithProduct(good1)
                                           .WithActualUnitPrice(3000)
                                           .WithQuantity(1)
                                           .WithMessage(@"line1
line2")
                                           .WithInvoiceItemType(new InvoiceItemTypes(this.Session).ProductItem)
                                           .Build();

                var purchaseInvoiceItem2 = new PurchaseInvoiceItemBuilder(this.Session)
                                           .WithDescription("second item")
                                           .WithActualUnitPrice(2000)
                                           .WithQuantity(2)
                                           .WithInvoiceItemType(new InvoiceItemTypes(this.Session).ProductItem)
                                           .Build();

                var purchaseInvoiceItem3 = new PurchaseInvoiceItemBuilder(this.Session)
                                           .WithDescription("Fee")
                                           .WithActualUnitPrice(100)
                                           .WithQuantity(1)
                                           .WithInvoiceItemType(new InvoiceItemTypes(this.Session).Fee)
                                           .Build();

                var purchaseInvoice = new PurchaseInvoiceBuilder(this.Session)
                                      .WithBilledTo(allors)
                                      .WithInvoiceNumber("1")
                                      .WithBilledFrom(acme)
                                      .WithPurchaseInvoiceItem(purchaseInvoiceItem1)
                                      .WithPurchaseInvoiceItem(purchaseInvoiceItem2)
                                      .WithPurchaseInvoiceItem(purchaseInvoiceItem3)
                                      .WithCustomerReference("a reference number")
                                      .WithDescription("Purchase of 1 used Aircraft Towbar")
                                      .WithPurchaseInvoiceType(new PurchaseInvoiceTypes(this.Session).PurchaseInvoice)
                                      .WithVatRegime(new VatRegimes(this.Session).Assessable)
                                      .Build();
            }

            this.Session.Derive();
        }
Ejemplo n.º 39
0
        public void GivenInvoiceItemForProductWithoutCategory_WhenDerivingSalesRep_ThenSalesRepForCustomerIsSelected()
        {
            this.InstantiateObjects(this.DatabaseSession);

            var salesrep1 = new PersonBuilder(this.DatabaseSession).WithLastName("salesrep for child product category").Build();
            var salesrep2 = new PersonBuilder(this.DatabaseSession).WithLastName("salesrep for parent category").Build();
            var salesrep3 = new PersonBuilder(this.DatabaseSession).WithLastName("salesrep for everything else").Build();
            var parentProductCategory = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("parent").Build();
            var childProductCategory = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("child").WithParent(parentProductCategory).Build();

            new SalesRepRelationshipBuilder(this.DatabaseSession)
                .WithFromDate(DateTime.UtcNow.AddMinutes(-1))
                .WithSalesRepresentative(salesrep1)
                .WithCustomer(this.invoice.BillToCustomer)
                .WithProductCategory(childProductCategory)
                .Build();

            new SalesRepRelationshipBuilder(this.DatabaseSession)
                .WithFromDate(DateTime.UtcNow.AddMinutes(-1))
                .WithSalesRepresentative(salesrep2)
                .WithCustomer(this.invoice.BillToCustomer)
                .WithProductCategory(parentProductCategory)
                .Build();

            new SalesRepRelationshipBuilder(this.DatabaseSession)
                .WithFromDate(DateTime.UtcNow.AddMinutes(-1))
                .WithSalesRepresentative(salesrep3)
                .WithCustomer(this.invoice.BillToCustomer)
                .Build();

            var invoiceItem = new SalesInvoiceItemBuilder(this.DatabaseSession)
                .WithProduct(this.good)
                .WithSalesInvoiceItemType(new SalesInvoiceItemTypes(this.DatabaseSession).ProductItem)
                .WithQuantity(3)
                .WithActualUnitPrice(5)
                .Build();

            this.invoice.AddSalesInvoiceItem(invoiceItem);

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(invoiceItem.SalesRep, salesrep3);
        }
Ejemplo n.º 40
0
        private static void CreateInvoiceItems(this WorkEffort @this, SalesInvoice salesInvoice)
        {
            var session           = @this.Strategy.Session;
            var timeBillingAmount = 0M;
            var hours             = 0M;
            var billableEntries   = new List <TimeEntry>();
            var frequencies       = new TimeFrequencies(session);

            foreach (TimeEntry timeEntry in @this.ServiceEntriesWhereWorkEffort)
            {
                if (timeEntry.IsBillable)
                {
                    billableEntries.Add(timeEntry);
                    var entryTimeSpan = (decimal)(timeEntry.ThroughDate - timeEntry.FromDate).Value.TotalMinutes;

                    if (timeEntry.ExistBillingRate)
                    {
                        var timeInTimeEntryRateFrequency = frequencies.Minute.ConvertToFrequency(entryTimeSpan, timeEntry.BillingFrequency);
                        timeBillingAmount += Math.Round((decimal)(timeEntry.BillingRate * timeInTimeEntryRateFrequency), 2);
                    }
                    else
                    {
                        var workEffortAssignmentRate      = @this.WorkEffortAssignmentRatesWhereWorkEffort.First;
                        var timeInWorkEffortRateFrequency = frequencies.Minute.ConvertToFrequency(entryTimeSpan, workEffortAssignmentRate.Frequency);
                        timeBillingAmount += Math.Round((decimal)(workEffortAssignmentRate.Rate * timeInWorkEffortRateFrequency), 2);
                    }
                }
            }

            if (timeBillingAmount > 0)
            {
                var invoiceItem = new SalesInvoiceItemBuilder(session)
                                  .WithInvoiceItemType(new InvoiceItemTypes(session).Time)
                                  .WithActualUnitPrice(timeBillingAmount)
                                  .WithQuantity(hours)
                                  .Build();

                salesInvoice.AddSalesInvoiceItem(invoiceItem);

                foreach (TimeEntry billableEntry in billableEntries)
                {
                    new TimeEntryBillingBuilder(session)
                    .WithTimeEntry(billableEntry)
                    .WithInvoiceItem(invoiceItem)
                    .Build();
                }
            }

            foreach (WorkEffortInventoryAssignment workEffortInventoryAssignment in @this.WorkEffortInventoryAssignmentsWhereAssignment)
            {
                var part            = workEffortInventoryAssignment.InventoryItem.Part;
                var priceComponents = GetPriceComponents(@this, part);

                var basePrice = 0M;
                foreach (var priceComponent in priceComponents)
                {
                    if (priceComponent.Strategy.Class.Equals(M.BasePrice.ObjectType))
                    {
                        if (priceComponent.ExistPrice)
                        {
                            if (basePrice < priceComponent.Price)
                            {
                                basePrice = (decimal)priceComponent.Price;
                            }
                        }
                    }
                }

                var invoiceItem = new SalesInvoiceItemBuilder(session)
                                  .WithInvoiceItemType(new InvoiceItemTypes(session).PartItem)
                                  .WithPart(part)
                                  .WithActualUnitPrice(basePrice)
                                  .WithQuantity(workEffortInventoryAssignment.Quantity)
                                  .Build();

                salesInvoice.AddSalesInvoiceItem(invoiceItem);

                new WorkEffortBillingBuilder(session)
                .WithWorkEffort(@this)
                .WithInvoiceItem(invoiceItem)
                .Build();
            }
        }
Ejemplo n.º 41
0
        public void GivenInvoiceItem_WhenBuild_ThenPostBuildRelationsMustExist()
        {
            this.InstantiateObjects(this.DatabaseSession);

            var item = new SalesInvoiceItemBuilder(this.DatabaseSession).WithSalesInvoiceItemType(new SalesInvoiceItemTypes(this.DatabaseSession).ProductItem).WithProduct(this.good).Build();

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(new SalesInvoiceItemObjectStates(this.DatabaseSession).ReadyForPosting, item.CurrentObjectState);
            Assert.AreEqual(item.CurrentObjectState, item.LastObjectState);
            Assert.AreEqual(0, item.AmountPaid);
            Assert.AreEqual(0, item.Quantity);
        }
Ejemplo n.º 42
0
        public void GivenInvoiceItem_WhenDeriving_ThenRequiredRelationsMustExist()
        {
            this.InstantiateObjects(this.DatabaseSession);

            var builder = new SalesInvoiceItemBuilder(this.DatabaseSession);
            builder.Build();

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

            this.DatabaseSession.Rollback();

            builder.WithProduct(this.good);
            builder.Build();

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

            this.DatabaseSession.Rollback();

            builder.WithQuantity(1);
            builder.Build();

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

            this.DatabaseSession.Rollback();

            builder.WithSalesInvoiceItemType(new SalesInvoiceItemTypes(this.DatabaseSession).ProductItem);
            builder.Build();

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

            this.DatabaseSession.Rollback();

            builder.WithProductFeature(this.feature1);
            builder.Build();

            Assert.IsTrue(this.DatabaseSession.Derive().HasErrors);
        }
Ejemplo n.º 43
0
        public void GiveninvoiceItem_WhenPartialPaymentIsReceived_ThenInvoiceItemStateIsSetToPartiallyPaid()
        {
            this.InstantiateObjects(this.DatabaseSession);

            var item1 = new SalesInvoiceItemBuilder(this.DatabaseSession)
                .WithProduct(this.good)
                .WithSalesInvoiceItemType(new SalesInvoiceItemTypes(this.DatabaseSession).ProductItem)
                .WithQuantity(1)
                .WithActualUnitPrice(100M)
                .Build();

            this.invoice.AddSalesInvoiceItem(item1);

            this.DatabaseSession.Derive(true);

            new ReceiptBuilder(this.DatabaseSession)
                .WithAmount(50)
                .WithPaymentApplication(new PaymentApplicationBuilder(this.DatabaseSession).WithInvoiceItem(item1).WithAmountApplied(50).Build())
                .WithEffectiveDate(DateTime.UtcNow)
                .Build();

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(new SalesInvoiceItemObjectStates(this.DatabaseSession).PartiallyPaid, item1.CurrentObjectState);
        }
Ejemplo n.º 44
0
        public void DeriveHistory()
        {
            var productItem = new SalesInvoiceItemTypes(this.DatabaseSession).ProductItem;
            var contactMechanism = new ContactMechanisms(this.DatabaseSession).Extent().First;

            var customer1 = new OrganisationBuilder(this.DatabaseSession).WithName("customer1").Build();
            var customer2 = new OrganisationBuilder(this.DatabaseSession).WithName("customer2").Build();
            var salesRep1 = new PersonBuilder(this.DatabaseSession).WithLastName("salesRep1").Build();
            var salesRep2 = new PersonBuilder(this.DatabaseSession).WithLastName("salesRep2").Build();
            var package1 = new PackageBuilder(this.DatabaseSession).WithName("package1").Build();
            var package2 = new PackageBuilder(this.DatabaseSession).WithName("package2").Build();
            var salesChannel1 = new SalesChannels(this.DatabaseSession).WebChannel;
            var salesChannel2 = new SalesChannels(this.DatabaseSession).NoChannel;
            var catMain = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("main cat").Build();
            var cat1 = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("cat for good1").WithParent(catMain).WithPackage(package1).Build();
            var cat2 = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("cat for good2").WithParent(catMain).WithPackage(package2).Build();

            new SalesRepRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer1).WithProductCategory(cat1).WithSalesRepresentative(salesRep1).Build();
            new SalesRepRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer1).WithProductCategory(cat2).WithSalesRepresentative(salesRep2).Build();

            this.DatabaseSession.Derive(true);

            new SalesRepRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer2).WithProductCategory(cat1).WithSalesRepresentative(salesRep1).Build();
            new SalesRepRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer2).WithProductCategory(cat2).WithSalesRepresentative(salesRep2).Build();

            this.DatabaseSession.Derive(true);

            var euro = new Currencies(this.DatabaseSession).FindBy(Currencies.Meta.IsoCode, "EUR");
            var vatRate21 = new VatRateBuilder(this.DatabaseSession).WithRate(21).Build();

            var good1 = new GoodBuilder(this.DatabaseSession)
                .WithSku("10101")
                .WithVatRate(vatRate21)
                .WithName("good1")
                .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .WithPrimaryProductCategory(cat1)
                .Build();

            var good2 = new GoodBuilder(this.DatabaseSession)
                .WithSku("10102")
                .WithVatRate(vatRate21)
                .WithName("good2")
                .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .WithPrimaryProductCategory(cat2)
                .Build();

            var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation");
            internalOrganisation.PreferredCurrency = euro;

            new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer1).WithInternalOrganisation(internalOrganisation).Build();
            new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer2).WithInternalOrganisation(internalOrganisation).Build();

            this.DatabaseSession.Derive(true);

            var invoice1 = new SalesInvoiceBuilder(this.DatabaseSession)
                .WithInvoiceDate(DateTime.UtcNow.AddMonths(-1))
                .WithInvoiceNumber("1")
                .WithBillToCustomer(customer1)
                .WithBillToContactMechanism(contactMechanism)
                .WithSalesChannel(salesChannel1)
                .WithSalesInvoiceType(new SalesInvoiceTypes(this.DatabaseSession).SalesInvoice)
                .Build();

            var item1a = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantity(3).WithActualUnitPrice(15).WithSalesInvoiceItemType(productItem).Build();
            invoice1.AddSalesInvoiceItem(item1a);

            var item1b = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantity(3).WithActualUnitPrice(15).WithSalesInvoiceItemType(productItem).Build();
            invoice1.AddSalesInvoiceItem(item1b);

            var item1c = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good2).WithQuantity(5).WithActualUnitPrice(10).WithSalesInvoiceItemType(productItem).Build();
            invoice1.AddSalesInvoiceItem(item1c);

            this.DatabaseSession.Derive(true);

            var invoice2 = new SalesInvoiceBuilder(this.DatabaseSession)
                .WithInvoiceDate(DateTime.UtcNow)
                .WithInvoiceNumber("1")
                .WithBillToCustomer(customer1)
                .WithBillToContactMechanism(contactMechanism)
                .WithSalesChannel(salesChannel1)
                .WithSalesInvoiceType(new SalesInvoiceTypes(this.DatabaseSession).SalesInvoice)
                .Build();

            var item2a = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantity(3).WithActualUnitPrice(15).WithSalesInvoiceItemType(productItem).Build();
            invoice2.AddSalesInvoiceItem(item2a);

            var item2b = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantity(3).WithActualUnitPrice(15).WithSalesInvoiceItemType(productItem).Build();
            invoice2.AddSalesInvoiceItem(item2b);

            var item2c = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good2).WithQuantity(5).WithActualUnitPrice(10).WithSalesInvoiceItemType(productItem).Build();
            invoice2.AddSalesInvoiceItem(item2c);

            this.DatabaseSession.Derive(true);

            Singleton.Instance(this.DatabaseSession).DeriveRevenues();

            var salesRep1RevenueHistory = salesRep1.SalesRepRevenueHistoriesWhereSalesRep.First;
            Assert.AreEqual(90, salesRep1RevenueHistory.Revenue);

            var salesRep2RevenueHistory = salesRep2.SalesRepRevenueHistoriesWhereSalesRep.First;
            Assert.AreEqual(50, salesRep2RevenueHistory.Revenue);

            var invoice3 = new SalesInvoiceBuilder(this.DatabaseSession)
                .WithInvoiceDate(DateTime.UtcNow)
                .WithInvoiceNumber("1")
                .WithBillToCustomer(customer2)
                .WithBillToContactMechanism(contactMechanism)
                .WithSalesChannel(salesChannel2)
                .WithSalesInvoiceType(new SalesInvoiceTypes(this.DatabaseSession).SalesInvoice)
                .Build();

            var item3a = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantity(1).WithActualUnitPrice(15).WithSalesInvoiceItemType(productItem).Build();
            invoice3.AddSalesInvoiceItem(item3a);

            var item3b = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good2).WithQuantity(1).WithActualUnitPrice(10).WithSalesInvoiceItemType(productItem).Build();
            invoice3.AddSalesInvoiceItem(item3b);

            this.DatabaseSession.Derive(true);

            Singleton.Instance(this.DatabaseSession).DeriveRevenues();

            Assert.AreEqual(105, salesRep1RevenueHistory.Revenue);
            Assert.AreEqual(60, salesRep2RevenueHistory.Revenue);
        }
Ejemplo n.º 45
0
        public void BaseInvoice(SalesOrderInvoice method)
        {
            if (this.CanInvoice)
            {
                var salesInvoice = new SalesInvoiceBuilder(this.Strategy.Session)
                                   .WithBilledFrom(this.TakenBy)
                                   .WithBilledFromContactMechanism(this.TakenByContactMechanism)
                                   .WithBilledFromContactPerson(this.TakenByContactPerson)
                                   .WithBillToCustomer(this.BillToCustomer)
                                   .WithBillToContactMechanism(this.BillToContactMechanism)
                                   .WithBillToContactPerson(this.BillToContactPerson)
                                   .WithBillToEndCustomer(this.BillToEndCustomer)
                                   .WithBillToEndCustomerContactMechanism(this.BillToEndCustomerContactMechanism)
                                   .WithBillToEndCustomerContactPerson(this.BillToEndCustomerContactPerson)
                                   .WithShipToCustomer(this.ShipToCustomer)
                                   .WithShipToAddress(this.ShipToAddress)
                                   .WithShipToContactPerson(this.ShipToContactPerson)
                                   .WithShipToEndCustomer(this.ShipToEndCustomer)
                                   .WithShipToEndCustomerAddress(this.ShipToEndCustomerAddress)
                                   .WithShipToEndCustomerContactPerson(this.ShipToEndCustomerContactPerson)
                                   .WithDescription(this.Description)
                                   .WithStore(this.Store)
                                   .WithInvoiceDate(this.Session().Now())
                                   .WithSalesChannel(this.SalesChannel)
                                   .WithSalesInvoiceType(new SalesInvoiceTypes(this.Strategy.Session).SalesInvoice)
                                   .WithVatRegime(this.VatRegime)
                                   .WithAssignedVatClause(this.DerivedVatClause)
                                   .WithDiscountAdjustment(this.DiscountAdjustment)
                                   .WithSurchargeAdjustment(this.SurchargeAdjustment)
                                   .WithShippingAndHandlingCharge(this.ShippingAndHandlingCharge)
                                   .WithFee(this.Fee)
                                   .WithCustomerReference(this.CustomerReference)
                                   .WithPaymentMethod(this.PaymentMethod)
                                   .WithCurrency(this.Currency)
                                   .Build();

                foreach (SalesOrderItem orderItem in this.ValidOrderItems)
                {
                    var amountAlreadyInvoiced = orderItem.OrderItemBillingsWhereOrderItem.Sum(v => v.Amount);

                    var leftToInvoice = (orderItem.QuantityOrdered * orderItem.UnitPrice) - amountAlreadyInvoiced;

                    if (leftToInvoice > 0)
                    {
                        var invoiceItem = new SalesInvoiceItemBuilder(this.Strategy.Session)
                                          .WithInvoiceItemType(orderItem.InvoiceItemType)
                                          .WithAssignedUnitPrice(orderItem.UnitPrice)
                                          .WithProduct(orderItem.Product)
                                          .WithQuantity(orderItem.CostOfGoodsSold)
                                          .WithCostOfGoodsSold(orderItem.QuantityOrdered)
                                          .WithAssignedVatRegime(orderItem.AssignedVatRegime)
                                          .WithDescription(orderItem.Description)
                                          .WithInternalComment(orderItem.InternalComment)
                                          .WithMessage(orderItem.Message)
                                          .Build();

                        if (orderItem.ExistSerialisedItem)
                        {
                            invoiceItem.SerialisedItem = orderItem.SerialisedItem;
                        }

                        salesInvoice.AddSalesInvoiceItem(invoiceItem);

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

                foreach (SalesTerm salesTerm in this.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());
                    }
                }
            }
        }