public static List <ZohoContactPerson> Map(IList <HSUser> users, ZohoContact contact = null) { // there is no property at this time for primary contact in OC, so we'll go with the first in the list var list = new List <ZohoContactPerson>(); foreach (var user in users) { if (contact?.contact_persons != null && contact.contact_persons.Any(p => p.email == user.Email)) { var c = contact.contact_persons.FirstOrDefault(p => p.email == user.Email); c.contact_person_id = c.contact_person_id; c.email = user.Email; c.first_name = user.FirstName; c.last_name = user.LastName; c.phone = user.Phone; list.Add(c); } else { list.Add(new ZohoContactPerson() { email = user.Email, first_name = user.FirstName, last_name = user.LastName, phone = user.Phone, }); } } return(list.DistinctBy(u => u.email).ToList()); }
public static ZohoContact Map(ZohoContact contact, HSSupplier supplier, HSAddressSupplier address, User user, ZohoCurrency currency) { return(new ZohoContact() { contact_id = contact.contact_id, company_name = supplier.ID, contact_name = supplier.Name, contact_type = "vendor", billing_address = ZohoAddressMapper.Map(address), shipping_address = ZohoAddressMapper.Map(address), contact_persons = contact.contact_persons = (contact.contact_persons != null && contact.contact_persons.Any(c => c.email == user.Email)) ? new List <ZohoContactPerson>() { new ZohoContactPerson() { email = user.Email, first_name = user.FirstName, last_name = user.LastName, phone = user.Phone } } : null, currency_id = currency.currency_id }); }
public static ZohoContact Map(ZohoContact contact, HSBuyer buyer, IList <HSUser> users, ZohoCurrency currency, HSBuyerLocation location) { contact.company_name = $"{buyer.Name} - {location.Address?.xp.LocationID}"; contact.contact_name = $"{location.Address?.AddressName} - {location.Address?.xp.LocationID}"; contact.contact_type = "customer"; contact.billing_address = ZohoAddressMapper.Map(location.Address); contact.shipping_address = ZohoAddressMapper.Map(location.Address); contact.contact_persons = ZohoContactMapper.Map(users, contact); contact.currency_id = currency.currency_id; contact.notes = $"Franchise ID: {buyer.ID} ~ Location ID: {location.Address?.xp.LocationID}"; return(contact); }
public Task <ZohoContact> CreateAsync(ZohoContact contact) => CreateAsync <ZohoContact>(contact);
public Task <ZohoContact> SaveAsync(ZohoContact contact) => SaveAsync <ZohoContact>(contact);
private async Task <ZohoSalesOrder> CreateSalesOrder(HSOrderWorksheet orderWorksheet, IEnumerable <ZohoLineItem> items, ZohoContact contact) { // promotions aren't part of the order worksheet, so we have to get them from OC var promotions = await _oc.Orders.ListPromotionsAsync(OrderDirection.Incoming, orderWorksheet.Order.ID); var zOrder = await _zoho.SalesOrders.ListAsync(new ZohoFilter() { Key = "reference_number", Value = orderWorksheet.Order.ID }); if (zOrder.Items.Any()) { return(await _zoho.SalesOrders.SaveAsync(ZohoSalesOrderMapper.Map(zOrder.Items.FirstOrDefault(), orderWorksheet, items.ToList(), contact, promotions.Items))); } return(await _zoho.SalesOrders.CreateAsync(ZohoSalesOrderMapper.Map(orderWorksheet, items.ToList(), contact, promotions.Items))); }
private async Task <ZohoPurchaseOrder> CreatePurchaseOrder(ZohoSalesOrder z_order, HSOrder order, List <ZohoLineItem> items, List <HSLineItem> lineitems, ZohoAddress delivery_address, ZohoContact contact) { var po = await _zoho.PurchaseOrders.ListAsync(new ZohoFilter() { Key = "purchaseorder_number", Value = order.ID }); if (po.Items.Any()) { return(await _zoho.PurchaseOrders.SaveAsync(ZohoPurchaseOrderMapper.Map(z_order, order, items, lineitems, delivery_address, contact, po.Items.FirstOrDefault()))); } return(await _zoho.PurchaseOrders.CreateAsync(ZohoPurchaseOrderMapper.Map(z_order, order, items, lineitems, delivery_address, contact))); }
public static ZohoSalesOrder Map(HSOrderWorksheet worksheet, List <ZohoLineItem> items, ZohoContact contact, IList <OrderPromotion> promotions) { var o = new ZohoSalesOrder() { reference_number = worksheet.Order.ID, salesorder_number = worksheet.Order.ID, date = worksheet.Order.DateSubmitted?.ToString("yyyy-MM-dd"), is_discount_before_tax = true, discount = decimal.ToDouble(promotions.Sum(p => p.Amount)), discount_type = "entity_level", line_items = worksheet.LineItems.Select(item => new ZohoLineItem { item_id = items.First(i => i.sku == item.SKU()).item_id, quantity = item.Quantity, rate = Math.Round((double)(item.UnitPrice ?? 0), 2), avatax_tax_code = item.Product.xp.Tax.Code //discount = decimal.ToDouble(promotions.Where(p => p.LineItemLevel == true && p.LineItemID == line_item.ID).Sum(p => p.Amount)), }).ToList(), tax_total = decimal.ToDouble(worksheet.Order.TaxCost), customer_name = contact.contact_name, sub_total = decimal.ToDouble(worksheet.Order.Subtotal), total = decimal.ToDouble(worksheet.Order.Total), customer_id = contact.contact_id, currency_code = contact.currency_code, currency_symbol = contact.currency_symbol, notes = promotions.Any() ? $"Promotions applied: {promotions.DistinctBy(p => p.Code).Select(p => p.Code).JoinString(" - ", p => p)}" : null //shipping_charge = decimal.ToDouble(order.ShippingCost), //TODO: Please mention any Shipping/miscellaneous charges as additional line items. }; // adding shipping as a line item foreach (var shipment in worksheet.ShipEstimateResponse.ShipEstimates) { var method = shipment.ShipMethods.FirstOrDefault(s => s.ID == shipment.SelectedShipMethodID); o.line_items.Add(new ZohoLineItem { item_id = items.First(i => i.sku == method?.ShippingSku()).item_id, quantity = 1, rate = Math.Round((double)(method?.Cost ?? 0), 2), avatax_tax_code = "FR" }); } return(o); }
public static ZohoPurchaseOrder Map(ZohoSalesOrder salesorder, Order order, List <ZohoLineItem> items, List <HSLineItem> lineitems, ZohoAddress delivery_address, ZohoContact vendor) { var po = new ZohoPurchaseOrder() { line_items = items.Select(p => new ZohoLineItem() { //account_id = p.purchase_account_id, item_id = p.item_id, description = p.description, rate = Math.Round(decimal.ToDouble(lineitems.First(l => l.SKU() == p.sku).UnitPrice.Value), 2), quantity = lineitems.First(l => l.SKU() == p.sku)?.Quantity }).ToList(), salesorder_id = salesorder.salesorder_id, purchaseorder_number = order.ID, reference_number = salesorder.reference_number, sub_total = decimal.ToDouble(order.Subtotal), tax_total = decimal.ToDouble(order.TaxCost), total = decimal.ToDouble(order.Total), vendor_id = vendor.contact_id, delivery_customer_id = salesorder.customer_id }; return(po); }