コード例 #1
0
        /// <summary>
        /// Maps an <see cref="IInvoice"/> to tax request.
        /// </summary>
        /// <param name="invoice">
        /// The invoice.
        /// </param>
        /// <param name="defaultStoreAddress">
        /// The default store address.  This is required for items without shipping information.
        /// </param>
        /// <param name="estimateOnly">
        /// Indicates if the quote should be an estimate or recorded
        /// </param>
        /// <returns>
        /// The <see cref="TaxRequest"/>.
        /// </returns>
        public static TaxRequest AsTaxRequest(this IInvoice invoice, ITaxAddress defaultStoreAddress, bool estimateOnly = true)
        {
            var addresses = new List <TaxAddress>();
            var lines     = new List <StatementLineItem>();

            defaultStoreAddress.AddressCode = "1";
            addresses.Add(defaultStoreAddress as TaxAddress);

            var shippingItems = invoice.ShippingLineItems().ToArray();

            if (shippingItems.Any())
            {
                var counter = 1;
                var lineNo  = 1;

                foreach (var shipLine in shippingItems)
                {
                    var shipment          = shipLine.ExtendedData.GetShipment <OrderLineItem>();
                    var shipmentAddresses = shipment.GetTaxAddressArray(counter + 1);

                    foreach (var line in shipment.Items)
                    {
                        lines.Add(
                            new StatementLineItem()
                        {
                            LineNo          = lineNo.ToString(CultureInfo.InvariantCulture).PadLeft(2, '0'),
                            ItemCode        = line.Sku,
                            Amount          = line.TotalPrice,
                            Qty             = line.Quantity,
                            Description     = line.Name,
                            OriginCode      = shipmentAddresses[0].AddressCode,
                            DestinationCode = shipmentAddresses[1].AddressCode
                        });
                        lineNo++;
                    }

                    lines.Add(new StatementLineItem()
                    {
                        LineNo          = string.Format("{0}-FR", lineNo.ToString(CultureInfo.InvariantCulture).PadLeft(2, '0')),
                        Amount          = shipLine.Price,
                        ItemCode        = shipLine.Sku,
                        Qty             = shipLine.Quantity,
                        Description     = shipLine.Name,
                        OriginCode      = shipmentAddresses[0].AddressCode,
                        DestinationCode = shipmentAddresses[1].AddressCode,
                        TaxCode         = "FR020100" // TODO this should probably not be hard coded here
                    });

                    addresses.AddRange(shipmentAddresses);
                    counter++;
                }
            }

            // add items not included in the shipment
            var notShipped =
                invoice.Items.Where(
                    x =>
                    x.LineItemType != LineItemType.Shipping &&
                    x.LineItemType != LineItemType.Discount &&
                    !lines.Any(line => line.ItemCode.Contains(x.Sku)));

            // TODO add lines for non shippable - like downloadable and discounts


            var taxRequest = new TaxRequest(estimateOnly ? StatementType.SalesOrder : StatementType.SalesInvoice)
            {
                DocCode   = invoice.PrefixedInvoiceNumber(),
                Addresses = addresses.ToArray(),
                DocDate   = invoice.InvoiceDate.ToString("yyyy-MM-dd"),
                Lines     = lines
            };

            return(taxRequest);
        }
コード例 #2
0
ファイル: MappingExtensions.cs プロジェクト: kedde/Merchello
        /// <summary>
        /// Maps an <see cref="IInvoice"/> to tax request.
        /// </summary>
        /// <param name="invoice">
        /// The invoice.
        /// </param>
        /// <param name="defaultStoreAddress">
        /// The default store address.  This is required for items without shipping information.
        /// </param>
        /// <returns>
        /// The <see cref="TaxRequest"/>.
        /// </returns>
        public static TaxRequest AsTaxRequest(this IInvoice invoice, ITaxAddress defaultStoreAddress)
        {
            var addresses = new List<TaxAddress>();
            var lines = new List<StatementLineItem>();

            defaultStoreAddress.AddressCode = "1";
            addresses.Add(defaultStoreAddress as TaxAddress);

            var shippingItems = invoice.ShippingLineItems().ToArray();
            if (shippingItems.Any())
            {
                var counter = 1;
                var lineNo = 1;

                foreach (var shipLine in shippingItems)
                {
                    var shipment = shipLine.ExtendedData.GetShipment<OrderLineItem>();
                    var shipmentAddresses = shipment.GetTaxAddressArray(counter + 1);

                    foreach (var line in shipment.Items)
                    {
                        lines.Add(
                                new StatementLineItem()
                                    {
                                        LineNo = lineNo.ToString(CultureInfo.InvariantCulture).PadLeft(2, '0'),
                                        ItemCode = line.Sku,
                                        Amount = line.TotalPrice,
                                        Qty = line.Quantity,
                                        Description = line.Name,
                                        OriginCode = shipmentAddresses[0].AddressCode,
                                        DestinationCode = shipmentAddresses[1].AddressCode
                                    });
                        lineNo++;
                    }

                    lines.Add(new StatementLineItem()
                        {
                            LineNo = string.Format("{0}-FR", lineNo.ToString(CultureInfo.InvariantCulture).PadLeft(2, '0')),
                            Amount = shipLine.Price,
                            ItemCode = shipLine.Sku,
                            Qty = shipLine.Quantity,
                            Description = shipLine.Name,
                            OriginCode = shipmentAddresses[0].AddressCode,
                            DestinationCode = shipmentAddresses[1].AddressCode,
                            TaxCode = "FR020200"
                        });

                    addresses.AddRange(shipmentAddresses);
                    counter++;
                }
            }

            // add items not included in the shipment
            var notShipped =
                invoice.Items.Where(
                    x =>
                    x.LineItemType != LineItemType.Shipping &&
                    x.LineItemType != LineItemType.Discount &&
                    !lines.Any(line => line.ItemCode.Contains(x.Sku)));

            var taxRequest = new TaxRequest()
                {
                    DocCode = invoice.PrefixedInvoiceNumber(),
                    Addresses = addresses.ToArray(),
                    DocDate = invoice.InvoiceDate.ToString("yyyy-MM-dd"),
                    Lines = lines
                };

            return taxRequest;
        }