public void BaseInvoice(PurchaseOrderInvoice method) { if (this.CanInvoice) { var purchaseInvoice = new PurchaseInvoiceBuilder(this.Strategy.Session) .WithBilledFrom(this.TakenViaSupplier) .WithBilledFromContactMechanism(this.TakenViaContactMechanism) .WithBilledFromContactPerson(this.TakenViaContactPerson) .WithBilledTo(this.OrderedBy) .WithBilledToContactPerson(this.BillToContactPerson) .WithDescription(this.Description) .WithInvoiceDate(this.Session().Now()) .WithVatRegime(this.VatRegime) .WithDiscountAdjustment(this.DiscountAdjustment) .WithSurchargeAdjustment(this.SurchargeAdjustment) .WithShippingAndHandlingCharge(this.ShippingAndHandlingCharge) .WithFee(this.Fee) .WithCustomerReference(this.CustomerReference) .WithPurchaseInvoiceType(new PurchaseInvoiceTypes(this.Session()).PurchaseInvoice) .Build(); foreach (PurchaseOrderItem orderItem in this.ValidOrderItems) { if (orderItem.CanInvoice) { var invoiceItem = new PurchaseInvoiceItemBuilder(this.Strategy.Session) .WithAssignedUnitPrice(orderItem.UnitPrice) .WithPart(orderItem.Part) .WithQuantity(orderItem.QuantityOrdered) .WithAssignedVatRegime(orderItem.AssignedVatRegime) .WithDescription(orderItem.Description) .WithInternalComment(orderItem.InternalComment) .WithMessage(orderItem.Message) .Build(); var invoiceItemTypes = new InvoiceItemTypes(this.Strategy.Session); invoiceItem.InvoiceItemType = invoiceItem.ExistPart ? invoiceItemTypes.PartItem : invoiceItemTypes.WorkDone; purchaseInvoice.AddPurchaseInvoiceItem(invoiceItem); new OrderItemBillingBuilder(this.Strategy.Session) .WithQuantity(orderItem.QuantityOrdered) .WithAmount(orderItem.TotalBasePrice) .WithOrderItem(orderItem) .WithInvoiceItem(invoiceItem) .Build(); } } } }
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); }