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