Ejemplo n.º 1
0
        public void AppsInvoice(SalesOrderInvoice method)
        {
            var derivation = new Derivation(this.Strategy.Session);

            this.AppsDeriveCanInvoice(derivation);

            if (this.CanInvoice)
            {
                this.AppsInvoiceThis(derivation);
            }
        }
Ejemplo n.º 2
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());
                    }
                }
            }
        }