public AddInvoiceItem ( InvoiceItem, newInvoiceItem ) : void | ||
newInvoiceItem | InvoiceItem, | |
return | void |
protected override void ExecuteInContext(IUnitOfWorkContext context, AddInvoiceItem command) { ITaxRepository taxRepo = NcqrsEnvironment.Get <ITaxRepository>(); Tax tax = taxRepo.FindByCode(command.TaxCode, command.OwnerId); Invoice invoice = context.GetById <Invoice>(command.InvoiceId, command.KnownVersion); invoice.AddInvoiceItem(command.ItemId, command.Description, command.Quantity, command.Price, command.DiscountInPercent, tax, command.OwnerId, command.UserName); context.Accept(); }
public void AddInvoiceItem(Product product, decimal price, decimal quantity, string description, decimal discount) { InvoiceDetails invoiceDetails = new InvoiceDetails(product, price, quantity, description, discount); invoice.AddInvoiceItem(invoiceDetails); }
private Invoice ProcessInvoiceLine(IReadOnlyDictionary <string, string> valuesFromAmazon, uint index, InvoiceConversionContext context) { var invoice = new Invoice(_vatPercentage); string shipCountry = valuesFromAmazon["ship-country"]; // TODO handle optional fields decimal promotionDiscount = 0; if (valuesFromAmazon.TryGetValue("item-promotion-discount", out string itemDiscount)) { promotionDiscount = decimal.Parse(itemDiscount); } if (valuesFromAmazon.TryGetValue("ship-promotion-discount", out string shippingDiscount)) { decimal shipPromotionDiscount = decimal.Parse(shippingDiscount); promotionDiscount += shipPromotionDiscount; // shipping discount se scita do total discount } string sku = valuesFromAmazon["sku"]; DateTime today = context.ConvertToDate; invoice.CurrencyName = _currencyConverter.Convert(valuesFromAmazon["currency"]); invoice.Number = context.ExistingInvoiceNumber + index; invoice.VariableSymbolFull = valuesFromAmazon["order-id"]; invoice.ShipCountryCode = shipCountry; invoice.ConversionDate = today; string clientName = FormatClientName(valuesFromAmazon["recipient-name"], invoice.VariableSymbolFull); string city = FormatCity(valuesFromAmazon["ship-city"], valuesFromAmazon["ship-state"], string.Empty, invoice.VariableSymbolFull); string fullAddress = FormatFullAddress(valuesFromAmazon["ship-address-1"], valuesFromAmazon["ship-address-2"], valuesFromAmazon["ship-address-3"], invoice.VariableSymbolFull); string phoneNumber = FormatPhoneNumber(valuesFromAmazon["ship-phone-number"], valuesFromAmazon["buyer-phone-number"], invoice.VariableSymbolFull); invoice.ClientInfo = new ClientInfo { Name = clientName, Address = new Address { City = city, Street = fullAddress, Country = shipCountry, Zip = valuesFromAmazon["ship-postal-code"] }, Contact = new ContactData { Email = context.DefaultEmail, Phone = phoneNumber } }; invoice.CustomsDeclaration = GetCustomsDeclarationBySkuOnlyForNonEu(sku, invoice.Classification); invoice.RelatedWarehouseName = GetSavedWarehouseBySku(sku); if (valuesFromAmazon.TryGetValue("sales-channel", out string salesChannelValue)) { invoice.SalesChannel = salesChannelValue; } var invoiceItems = new List <InvoiceItemBase>(); var invoiceProduct = new InvoiceProduct(invoice) { WarehouseCode = GetSavedItemCodeBySku(sku), AmazonSku = sku }; var invoiceItemProduct = FillInvoiceItem( invoiceProduct, valuesFromAmazon["product-name"], decimal.Parse(valuesFromAmazon["item-price"]), decimal.Parse(valuesFromAmazon["item-tax"]), decimal.Parse(valuesFromAmazon["quantity-purchased"])); invoiceProduct.PackQuantityMultiplier = 1; if (!string.IsNullOrEmpty(invoiceProduct.AmazonSku) && _autocompleteData.PackQuantitySku.ContainsKey(invoiceProduct.AmazonSku)) { invoiceProduct.PackQuantityMultiplier = uint.Parse(_autocompleteData.PackQuantitySku[invoiceProduct.AmazonSku]); } invoiceItems.Add(invoiceItemProduct); var invoiceItemShipping = FillInvoiceItem( new InvoiceItemGeneral(invoice, InvoiceItemType.Shipping), GetSavedShippingType(sku, invoice.ClientInfo, invoice.Classification), decimal.Parse(valuesFromAmazon["shipping-price"]), decimal.Parse(valuesFromAmazon["shipping-tax"]), 1); invoiceItems.Add(invoiceItemShipping); if (promotionDiscount != 0) { var invoiceItemDiscount = FillInvoiceItem( new InvoiceItemGeneral(invoice, InvoiceItemType.Discount), "Discount", promotionDiscount, 0, 1); invoiceItems.Add(invoiceItemDiscount); } // TODO fix if (valuesFromAmazon.TryGetValue("gift-wrap-price", out var giftWrapPrice) && // columns are not always available in the amazon invoice valuesFromAmazon.TryGetValue("gift-wrap-tax", out var giftWrapTax) && decimal.TryParse(giftWrapPrice, out var giftWrapPriceValue) && giftWrapPriceValue != 0) { decimal giftWrapTaxVal = 0; if (decimal.TryParse(giftWrapTax, out var valueTax)) { giftWrapTaxVal = valueTax; } string giftWrapType = "Gift wrap " + valuesFromAmazon["gift-wrap-type"]; var invoiceItemGiftWrap = FillInvoiceItem( new InvoiceItemGeneral(invoice, InvoiceItemType.GiftWrap), giftWrapType, giftWrapPriceValue, giftWrapTaxVal, 1); invoiceItems.Add(invoiceItemGiftWrap); } foreach (var item in invoiceItems) { invoice.AddInvoiceItem(item); } return(invoice); }