internal clientinvoice ToNative() { return(new clientinvoice { debitinvoicenr = DebitInvoiceNr.GetValueOrDefault(), debitinvoicenrSpecified = DebitInvoiceNr.HasValue, foreignid = ForeignId ?? string.Empty, ponr = PoNr ?? string.Empty, clientref = new clientreference { id = ClientId }, clientinvoicetemplateref = ClientInvoiceTemplateId.HasValue ? new clientinvoicetemplatereference { id = ClientInvoiceTemplateId.Value } : null, yourreference = YourReference ?? string.Empty, ourreference = new userreference { id = OurReferenceUserId.GetValueOrDefault(0) }, // 0 = not set according to docs approver = new userreference { id = ApproverUserId.GetValueOrDefault(0) }, // 0 = not set according to docs invoicedate = InvoiceDate, invoiceaddress = InvoiceAddress != null?InvoiceAddress.ToNative() : new Address().ToNative(), invoiceemail = InvoiceEmail ?? string.Empty, deliverydate = DeliveryDate ?? default(DateTime), deliveryname = DeliveryName ?? string.Empty, deliverytype = DeliveryType ?? string.Empty, deliveryaddress = DeliveryAddress != null?DeliveryAddress.ToNative() : new Address().ToNative(), deliveryemail = DeliveryEmail ?? string.Empty, duedate = DueDate, period = Period?.ToNative(), currency = Currency ?? string.Empty, currencyrate = CurrencyRate.GetValueOrDefault(), currencyrateSpecified = CurrencyRate.HasValue, certified = IsCertified, notes = Notes ?? string.Empty, gln = Gln ?? string.Empty, vatnr = VatNr ?? string.Empty, countrycode = CountryCode ?? string.Empty, disabled = IsDisabled, automaticactionsdisabled = IsAutomaticActionsDisabled.GetValueOrDefault(), automaticactionsdisabledSpecified = IsAutomaticActionsDisabled.HasValue, automaticactionsmessage = AutomaticActionsMessage ?? string.Empty, fields = Fields?.Select(x => x.ToNative()).ToArray(), files = Files?.Select(x => x.ToNative()).ToArray(), rows = Rows?.Select(x => x.ToNative()).ToArray() }); }
public static InvoiceAddressVm MapToViewModel(InvoiceAddress source) { var config = new MapperConfiguration(cfg => cfg.CreateMap <InvoiceAddress, InvoiceAddressVm>() ); var mapper = config.CreateMapper(); var destination = mapper.Map <InvoiceAddressVm>(source); return(destination); }
public override int GetHashCode() { unchecked { var result = NamedTupleCommon.DefaultHashCode; result = (result << 5) + result ^ (Id.GetHashCode()); result = (result << 5) + result ^ (FirstName != null ? FirstName.GetHashCode() : NamedTupleCommon.DefaultHashCode); result = (result << 5) + result ^ (LastName != null ? LastName.GetHashCode() : NamedTupleCommon.DefaultHashCode); result = (result << 5) + result ^ (NamedTupleCommon.StructuralGetHashCode(Aliases)); result = (result << 5) + result ^ (InvoiceAddress != null ? InvoiceAddress.GetHashCode() : NamedTupleCommon.DefaultHashCode); result = (result << 5) + result ^ (DeliveryAddress != null ? DeliveryAddress.GetHashCode() : NamedTupleCommon.DefaultHashCode); return(result); } }
private static Invoice GetInvoice(dynamic json) { if (json is JArray) { return(null); } var address = new InvoiceAddress((string)json.address_1, (string)json.address_2, (string)json.address_3, (string)json.address_4, (string)json.address_5, (string)json.address_6); var invoice = new Invoice((DateTime)json.date, (string)json.number, (decimal)json.total, (decimal)json.tax, (string)json.pdf_url, address); foreach (var iL in json.invoice_lines) { var invoiceLine = new InvoiceLine((int)iL.quantity, (string)iL.details, (decimal)iL.unit_price, (decimal)iL.subtotal); invoice.AddLine(invoiceLine); } return(invoice); }
public override string ToString() { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine(FullName); AppendMyLine(stringBuilder); if (HasHomeAddress) { stringBuilder.AppendLine("Adres domowy:"); stringBuilder.AppendLine(HomeAddress.ToString()); AppendMyLine(stringBuilder); } if (HasInvoiceAddress) { stringBuilder.AppendLine("Adres fakturowania:"); stringBuilder.AppendLine(InvoiceAddress.ToString()); AppendMyLine(stringBuilder); } return(stringBuilder.ToString()); }
internal void ReadInvoice(string editext) { List<Invoice> invoices = new List<Invoice>(); List<InvoiceItem> items = new List<InvoiceItem>(); List<InvoiceCode> codes = new List<InvoiceCode>(); Dictionary<string, string> itdcodes = new Dictionary<string, string>(); itdcodes.Add("01", "Basic"); itdcodes.Add("02", "End of Month"); itdcodes.Add("03", "Fixed Date"); itdcodes.Add("04", "Def. or installment"); itdcodes.Add("05", "Discount N/A"); itdcodes.Add("08", "Basic disc. offered"); itdcodes.Add("09", "Proximo"); itdcodes.Add("12", "10 days after EOM"); itdcodes.Add("14", "Previously agreed"); itdcodes.Add("17", "Terms N/A"); itdcodes.Add("ZZ", "Mutually Defined"); Invoice inv = new Invoice(); InvoiceAddress address = new InvoiceAddress(); char billorship = 'b'; List<string> edilines = editext.Split('~').ToList<string>(); foreach (string line in edilines) { List<string> lineelements = line.Split('*').ToList<string>(); switch (lineelements[0]) { case "ST": // Beginning of invoice inv = new Invoice(); items = new List<InvoiceItem>(); codes = new List<InvoiceCode>(); break; case "BIG": // Beginning statement string dt = lineelements[1].Substring(4, 2) + "-" + lineelements[1].Substring(6, 2) + "-" + lineelements[1].Substring(0, 4); inv.dateAdded = Convert.ToDateTime(dt); inv.number = lineelements[2]; inv.orderID = lineelements[4]; switch (lineelements[7]) { case "CN": inv.invoiceType = "Credit Invoice"; break; case "DI": inv.invoiceType = "Debit Invoice"; break; case "ZZ": inv.invoiceType = "Mutually Defined"; break; } break; case "CUR": inv.billToCurrency = lineelements[2]; break; case "REF": inv.curtOrder = Convert.ToInt32(lineelements[2].Trim()); break; case "N1": switch (lineelements[1]) { case "RI": inv.remitTo = lineelements[4]; break; case "BT": billorship = 'b'; address = new InvoiceAddress(); string[] namesplit = lineelements[2].Split(' '); address.first = namesplit[0]; try { address.last = namesplit[1]; } catch { address.last = ""; } break; case "ST": billorship = 's'; address = new InvoiceAddress(); namesplit = lineelements[2].Split(' '); address.first = namesplit[0]; try { address.last = namesplit[1]; } catch { address.last = ""; } break; } break; case "N2": break; case "N3": address.street1 = lineelements[1]; try { address.street2 = lineelements[2]; } catch { address.street2 = ""; } break; case "N4": address.city = lineelements[1]; address.state = lineelements[2]; address.postal_code = lineelements[3]; address.MatchOrSave(); if (billorship == 'b') inv.billTo = address.ID; else inv.shipTo = address.ID; break; case "ITD": // invoice due statement inv.termsType = itdcodes[lineelements[1]]; inv.discountPercent = Convert.ToDecimal(lineelements[3]); if (lineelements[4].Length == 8) { inv.discountDueDate = Convert.ToDateTime(lineelements[4].Substring(4, 2) + "-" + lineelements[4].Substring(6, 2) + "-2" + lineelements[4].Substring(1, 3)); } inv.discountDueDays = Convert.ToInt32(lineelements[5]); inv.netDueDate = Convert.ToDateTime(lineelements[6].Substring(4, 2) + "-" + lineelements[6].Substring(6, 2) + "-2" + lineelements[6].Substring(1, 3)); inv.netDueDays = Convert.ToInt32(lineelements[7]); inv.termsDescription = lineelements[12]; break; case "IT1": // item in the invoice InvoiceItem i = new InvoiceItem(); try { i.quantity = Convert.ToInt32(lineelements[2]); } catch { i.quantity = 0; } i.price = (lineelements[4].Length > 0) ? Convert.ToDecimal(lineelements[4]) : 0; i.partID = lineelements[9]; i.description = lineelements[15]; /*InvoiceItem i = new InvoiceItem { quantity = Convert.ToInt32(lineelements[2]), price = Convert.ToDecimal(lineelements[4]), partID = lineelements[9], description = lineelements[15] };*/ items.Add(i); break; case "TDS": // totals inv.total = (Convert.ToDecimal(lineelements[1]) / 100); try { inv.subtotal = (Convert.ToDecimal(lineelements[2]) / 100); } catch { }; try { inv.discountTotal = (Convert.ToDecimal(lineelements[3]) / 100); } catch { }; try { inv.discount = (Convert.ToDecimal(lineelements[4]) / 100); } catch { }; break; case "TXI": // special tax line for canadians inv.salesTax = Convert.ToDecimal(lineelements[2]); break; case "SAC": // special codes InvoiceCode c = new InvoiceCode { type = (lineelements[1] == "C") ? "Charge" : "Allowance", code = lineelements[2], value = (Convert.ToDecimal(lineelements[5]) / 100), description = lineelements[15] }; codes.Add(c); break; case "SE": // End of Invoice inv.Save(items, codes); break; } } }
public ActionResult SubmitOrder([Bind(Include = "FirstName, LastName, Email, PhoneNumber, Country, City, Address, PostalCode")] InvoiceAddressVM a) { // Create Order decimal orderTotal = 0; decimal rowAmount = 0; DateTime wDate; var context = new AppDbContext(); var order = new Order(); order.OrderDate = DateTime.Now; wDate = order.OrderDate; order.Total = 0; var cId = Session["SessId"] as string; order.CartId = cId; order.Email = a.Email; context.Orders.Add(order); var affectedRows = context.SaveChanges(); // Get order id from Order table int wOrderId = 0; var orders = context.Orders.ToList().Select(x => new Order { CartId = x.CartId, OrderId = x.OrderId, }).ToList(); foreach (var item in orders) { if (item.CartId == cId && item.OrderId > wOrderId) { wOrderId = item.OrderId; } } // -------------------------------------------------- // Save OrderId if (Session["OrderId"] == null) { Session.Add("OrderId", wOrderId); } // -------------------------------------------------- if (wOrderId != 0) { var carts = context.Carts.ToList().Select(x => new Cart { CartId = x.CartId, ItemId = x.ItemId, Price = x.Price, Quantity = x.Quantity, DateCreated = x.DateCreated, }).ToList(); if (carts != null) { foreach (var item in carts) { if (item.CartId == cId) { var od = new OrderDetail(); od.OrderId = wOrderId; od.ItemId = item.ItemId; od.Quantity = item.Quantity; od.UnitPrice = item.Price; // add to ordertotal rowAmount = item.Price * item.Quantity; orderTotal = orderTotal + rowAmount; context.OrderDetails.Add(od); affectedRows = context.SaveChanges(); } } // update total amount in Order table // or = context.Orders.FirstOrDefault(x => x.CartId == cId); var or = context.Orders.FirstOrDefault(x => x.OrderId == wOrderId); if (or != null) { or.Total = orderTotal; context.SaveChanges(); } } // create or update Invoice Address var iAdr = new InvoiceAddress(); iAdr.FirstName = a.FirstName; iAdr.LastName = a.LastName; iAdr.Email = a.Email; iAdr.PhoneNumber = a.PhoneNumber; iAdr.Country = a.Country; iAdr.City = a.City; iAdr.Address = a.Address; iAdr.PostalCode = a.PostalCode; // -------------------------------------------------- // Save Email address // Used as key in Invoice Address table if (Session["Email"] == null) { string wem = a.Email; Session.Add("Email", wem); } // -------------------------------------------------- var ia = context.InvoiceAddresses.FirstOrDefault(x => x.Email == a.Email); if (ia == null) { context.InvoiceAddresses.Add(iAdr); affectedRows = context.SaveChanges(); } else { context.SaveChanges(); } } //return View("CheckOut", a); return(RedirectToAction("OrderConfirm", "Shop")); }
public bool Equals(Customer other) { if (other == null) { return(false); } var result = (Id.Equals(other.Id)) && ((FirstName ?? "").Equals(other.FirstName ?? "", NamedTupleCommon.DefaultStringComparison)) && ((LastName ?? "").Equals(other.LastName ?? "", NamedTupleCommon.DefaultStringComparison)) && (NamedTupleCommon.StructuralEqual(Aliases, other.Aliases)) && (InvoiceAddress == null && other.InvoiceAddress == null || InvoiceAddress != null && other.InvoiceAddress != null && InvoiceAddress.Equals(other.InvoiceAddress)) && (DeliveryAddress == null && other.DeliveryAddress == null || DeliveryAddress != null && other.DeliveryAddress != null && DeliveryAddress.Equals(other.DeliveryAddress)) ; return(result); }