/// <summary>
        /// Converts a Lucene cached invoice into <see cref="InvoiceDisplay"/>
        /// </summary>
        /// <param name="result">
        /// The result.
        /// </param>
        /// <param name="getOrders">
        /// The get Orders.
        /// </param>
        /// <returns>
        /// The <see cref="InvoiceDisplay"/>.
        /// </returns>
        internal static InvoiceDisplay ToInvoiceDisplay(this SearchResult result, Func <Guid, IEnumerable <OrderDisplay> > getOrders)
        {
            var invoice = new InvoiceDisplay()
            {
                Key = FieldAsGuid(result, "invoiceKey"),
                InvoiceNumberPrefix = FieldAsString(result, "invoiceNumberPrefix"),
                InvoiceNumber       = FieldAsInteger(result, "invoiceNumber"),
                InvoiceDate         = FieldAsDateTime(result, "invoiceDate"),
                InvoiceStatusKey    = FieldAsGuid(result, "invoiceStatusKey"),
                CustomerKey         = FieldAsGuid(result, "customerKey"),
                VersionKey          = FieldAsGuid(result, "versionKey"),
                BillToName          = FieldAsString(result, "billToName"),
                BillToAddress1      = FieldAsString(result, "billToAddress1"),
                BillToAddress2      = FieldAsString(result, "billToAddress2"),
                BillToLocality      = FieldAsString(result, "billToLocality"),
                BillToRegion        = FieldAsString(result, "billoToRegion"),
                BillToCountryCode   = FieldAsString(result, "billToCountryCode"),
                BillToPostalCode    = FieldAsString(result, "billToPostalCode"),
                BillToCompany       = FieldAsString(result, "billToCompany"),
                BillToPhone         = FieldAsString(result, "billToPhone"),
                BillToEmail         = FieldAsString(result, "billToEmail"),
                PoNumber            = FieldAsString(result, "poNumber"),
                Exported            = FieldAsBoolean(result.Fields["exported"]),
                Archived            = FieldAsBoolean(result.Fields["archived"]),
                Total         = FieldAsDecimal(result, "total"),
                InvoiceStatus = JsonFieldAs <InvoiceStatusDisplay>(result, "invoiceStatus"),
                Items         = RawJsonFieldAsCollection <InvoiceLineItemDisplay>(result, "invoiceItems"),
            };

            invoice.Orders = getOrders(invoice.Key);

            return(invoice);
        }
Exemplo n.º 2
0
        internal static IInvoice ToInvoice(this InvoiceDisplay invoiceDisplay, IInvoice destination)
        {
            if (invoiceDisplay.Key != Guid.Empty)
            {
                destination.Key = invoiceDisplay.Key;
            }
            destination.InvoiceNumberPrefix = invoiceDisplay.InvoiceNumberPrefix;
            destination.InvoiceDate         = invoiceDisplay.InvoiceDate;
            destination.InvoiceStatus       = invoiceDisplay.InvoiceStatus.ToInvoiceStatus();
            destination.VersionKey          = invoiceDisplay.VersionKey;
            destination.BillToName          = invoiceDisplay.BillToName;
            destination.BillToAddress1      = invoiceDisplay.BillToAddress1;
            destination.BillToAddress2      = invoiceDisplay.BillToAddress2;
            destination.BillToLocality      = invoiceDisplay.BillToLocality;
            destination.BillToRegion        = invoiceDisplay.BillToRegion;
            destination.BillToPostalCode    = invoiceDisplay.BillToPostalCode;
            destination.BillToCountryCode   = invoiceDisplay.BillToCountryCode;
            destination.BillToEmail         = invoiceDisplay.BillToEmail;
            destination.BillToPhone         = invoiceDisplay.BillToPhone;
            destination.BillToCompany       = invoiceDisplay.BillToCompany;
            destination.Exported            = invoiceDisplay.Exported;
            destination.Archived            = invoiceDisplay.Archived;
            destination.PoNumber            = invoiceDisplay.PoNumber;

            // set the note type field key
            var invoiceTfKey = Constants.TypeFieldKeys.Entity.InvoiceKey;

            foreach (var idn in invoiceDisplay.Notes)
            {
                idn.EntityTfKey = invoiceTfKey;
            }

            // remove or update any notes that were previously saved and/or removed through the back office
            var updateNotes = invoiceDisplay.Notes.Where(x => x.Key != Guid.Empty).ToArray();

            var notes      = destination.Notes.ToList();
            var removeKeys = new List <Guid>();

            foreach (var n in notes)
            {
                var update = updateNotes.FirstOrDefault(x => x.Key == n.Key);
                if (update == null)
                {
                    removeKeys.Add(n.Key);
                }
                else
                {
                    n.Message      = update.Message;
                    n.InternalOnly = update.InternalOnly;
                }
            }

            notes.AddRange(invoiceDisplay.Notes.Where(x => x.Key == Guid.Empty).Select(x => x.ToNote()));

            destination.Notes = notes.Where(x => removeKeys.All(y => y != x.Key));

            return(destination);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Utility extension method to add an <see cref="IAddress"/> to an <see cref="IInvoice"/>
 /// </summary>
 /// <param name="invoice">The <see cref="IInvoice"/> to which to set the address information</param>
 /// <param name="address">The billing address <see cref="IAddress"/></param>
 public static void SetBillingAddress(this InvoiceDisplay invoice, IAddress address)
 {
     invoice.BillToName        = address.Name;
     invoice.BillToCompany     = address.Organization;
     invoice.BillToAddress1    = address.Address1;
     invoice.BillToAddress2    = address.Address2;
     invoice.BillToLocality    = address.Locality;
     invoice.BillToRegion      = address.Region;
     invoice.BillToPostalCode  = address.PostalCode;
     invoice.BillToCountryCode = address.CountryCode;
     invoice.BillToPhone       = address.Phone;
     invoice.BillToEmail       = address.Email;
 }
Exemplo n.º 4
0
 /// <summary>
 /// Utility extension to extract the billing <see cref="IAddress"/> from an <see cref="IInvoice"/>
 /// </summary>
 /// <param name="invoice">The invoice</param>
 /// <returns>
 /// The billing address saved in the invoice
 /// </returns>
 public static IAddress GetBillingAddress(this InvoiceDisplay invoice)
 {
     return(new Address()
     {
         Name = invoice.BillToName,
         Organization = invoice.BillToCompany,
         Address1 = invoice.BillToAddress1,
         Address2 = invoice.BillToAddress2,
         Locality = invoice.BillToLocality,
         Region = invoice.BillToRegion,
         PostalCode = invoice.BillToPostalCode,
         CountryCode = invoice.BillToCountryCode,
         Phone = invoice.BillToPhone,
         Email = invoice.BillToEmail
     });
 }
Exemplo n.º 5
0
        /// <summary>
        /// Converts a Lucene cached invoice into <see cref="InvoiceDisplay"/>
        /// </summary>
        /// <param name="result">
        /// The result.
        /// </param>
        /// <param name="getOrders">
        /// The get Orders.
        /// </param>
        /// <returns>
        /// The <see cref="InvoiceDisplay"/>.
        /// </returns>
        internal static InvoiceDisplay ToInvoiceDisplay(this SearchResult result, Func <Guid, IEnumerable <OrderDisplay> > getOrders)
        {
            var invoice = new InvoiceDisplay()
            {
                Key = FieldAsGuid(result, "invoiceKey"),
                InvoiceNumberPrefix = FieldAsString(result, "invoiceNumberPrefix"),
                InvoiceNumber       = FieldAsInteger(result, "invoiceNumber"),
                InvoiceDate         = FieldAsDateTime(result, "invoiceDate"),
                InvoiceStatusKey    = FieldAsGuid(result, "invoiceStatusKey"),
                CustomerKey         = FieldAsGuid(result, "customerKey"),
                VersionKey          = FieldAsGuid(result, "versionKey"),
                BillToName          = FieldAsString(result, "billToName"),
                BillToAddress1      = FieldAsString(result, "billToAddress1"),
                BillToAddress2      = FieldAsString(result, "billToAddress2"),
                BillToLocality      = FieldAsString(result, "billToLocality"),
                BillToRegion        = FieldAsString(result, "billoToRegion"),
                BillToCountryCode   = FieldAsString(result, "billToCountryCode"),
                BillToPostalCode    = FieldAsString(result, "billToPostalCode"),
                BillToCompany       = FieldAsString(result, "billToCompany"),
                BillToPhone         = FieldAsString(result, "billToPhone"),
                BillToEmail         = FieldAsString(result, "billToEmail"),
                PoNumber            = FieldAsString(result, "poNumber"),
                Exported            = FieldAsBoolean(result.Fields["exported"]),
                Archived            = FieldAsBoolean(result.Fields["archived"]),
                Total         = FieldAsDecimal(result, "total"),
                InvoiceStatus = JsonFieldAs <InvoiceStatusDisplay>(result, "invoiceStatus"),
                Items         = RawJsonFieldAsCollection <InvoiceLineItemDisplay>(result, "invoiceItems"),
            };

            // TODO - this is sort of hacky and should be revisited.
            foreach (var item in invoice.Items)
            {
                var tf        = EnumTypeFieldConverter.LineItemType.GetTypeField(item.LineItemTfKey);
                var lineTfKey = item.LineItemTfKey;
                item.LineItemTypeField = tf == LineItemType.Custom ?
                                         (TypeField)EnumTypeFieldConverter.LineItemType.CustomTypeFields.FirstOrDefault(x => x.TypeKey == lineTfKey) :
                                         (TypeField)EnumTypeFieldConverter.LineItemType.GetTypeField(tf);
            }


            invoice.Orders = getOrders(invoice.Key);

            return(invoice);
        }
 internal static IInvoice ToInvoice(this InvoiceDisplay invoiceDisplay, IInvoice destination)
 {
     if (invoiceDisplay.Key != Guid.Empty)
     {
         destination.Key = invoiceDisplay.Key;
     }
     destination.InvoiceNumberPrefix = invoiceDisplay.InvoiceNumberPrefix;
     destination.InvoiceDate         = invoiceDisplay.InvoiceDate;
     destination.InvoiceStatus       = invoiceDisplay.InvoiceStatus.ToInvoiceStatus();
     destination.VersionKey          = invoiceDisplay.VersionKey;
     destination.BillToName          = invoiceDisplay.BillToName;
     destination.BillToAddress1      = invoiceDisplay.BillToAddress1;
     destination.BillToAddress2      = invoiceDisplay.BillToAddress2;
     destination.BillToLocality      = invoiceDisplay.BillToLocality;
     destination.BillToRegion        = invoiceDisplay.BillToRegion;
     destination.BillToPostalCode    = invoiceDisplay.BillToPostalCode;
     destination.BillToCountryCode   = invoiceDisplay.BillToCountryCode;
     destination.BillToEmail         = invoiceDisplay.BillToEmail;
     destination.BillToPhone         = invoiceDisplay.BillToPhone;
     destination.BillToCompany       = invoiceDisplay.BillToCompany;
     destination.Exported            = invoiceDisplay.Exported;
     destination.Archived            = invoiceDisplay.Archived;
     return(destination);
 }
Exemplo n.º 7
0
        public HttpResponseMessage PutInvoice(InvoiceDisplay invoice)
        {
            var response = Request.CreateResponse(HttpStatusCode.OK);

            try
            {
                var merchInvoice = _invoiceService.GetByKey(invoice.Key);

                merchInvoice = invoice.ToInvoice(merchInvoice);

                _invoiceService.Save(merchInvoice);
            }
            catch (Exception ex)
            {
                MultiLogHelper.Error<InvoiceApiController>("Failed to save invoice", ex);
                response = Request.CreateResponse(HttpStatusCode.NotFound, string.Format("{0}", ex.Message));
            }

            return response;
        }
Exemplo n.º 8
0
 /// <summary>
 /// Gets an invoice number with a prefix (if any).
 /// </summary>
 /// <param name="invoice">
 /// The invoice.
 /// </param>
 /// <returns>
 /// The prefixed invoice number.
 /// </returns>
 public static string PrefixedInvoiceNumber(this InvoiceDisplay invoice)
 {
     return(string.IsNullOrEmpty(invoice.InvoiceNumberPrefix)
         ? invoice.InvoiceNumber.ToString(CultureInfo.InvariantCulture)
         : string.Format("{0}-{1}", invoice.InvoiceNumberPrefix, invoice.InvoiceNumber));
 }
Exemplo n.º 9
0
        public HttpResponseMessage PutInvoice(InvoiceDisplay invoice)
        {
            var response = Request.CreateResponse(HttpStatusCode.OK);

            try
            {
                var merchInvoice = _invoiceService.GetByKey(invoice.Key);
                merchInvoice = invoice.ToInvoice(merchInvoice);

                _invoiceService.Save(merchInvoice);
            }
            catch (Exception ex)
            {
                response = Request.CreateResponse(HttpStatusCode.NotFound, string.Format("{0}", ex.Message));
            }

            return response;
        }