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 async Task <List <ZohoPurchaseOrder> > CreateShippingPurchaseOrder(ZohoSalesOrder z_order, HSOrderWorksheet order) { // special request by SMG for creating PO of shipments // we definitely don't want this stopping orders from flowing into Zoho so I'm going to handle exceptions and allow to proceed try { var list = new List <ZohoPurchaseOrder>(); foreach (var item in order.ShipEstimateResponse.ShipEstimates) { var shipping_method = item.ShipMethods.FirstOrDefault(s => s.ID == item.SelectedShipMethodID); if (shipping_method.xp.CarrierAccountID != "ca_8bdb711131894ab4b42abcd1645d988c") { continue; } var vendor = await _zoho.Contacts.ListAsync(new ZohoFilter() { Key = "contact_name", Value = "SMG Shipping" }); var oc_lineitems = new ListPage <HSLineItem>() { Items = new List <HSLineItem>() { new HSLineItem() { ID = $"{z_order.reference_number} - {ZohoExtensions.ShippingSuffix}", UnitPrice = shipping_method?.Cost, ProductID = shipping_method.ShippingSku(), SupplierID = "SMG Shipping", Product = new HSLineItemProduct() { Description = $"{shipping_method?.xp?.Carrier} Shipping Charge", Name = shipping_method.ShippingSku(), ID = shipping_method.ShippingSku(), QuantityMultiplier = 1, xp = new ProductXp() { Tax = new TaxProperties() { Code = "FR", Description = "Shipping Charge" } } } } } }; var z_item = await CreateOrUpdateShippingLineItem(oc_lineitems.Items); var oc_order = new Order() { ID = $"{order.Order.ID}-{order.LineItems.FirstOrDefault()?.SupplierID} - 41000", Subtotal = shipping_method.Cost, Total = shipping_method.Cost, TaxCost = 0M }; var oc_lineitem = new ListPage <HSLineItem>() { Items = new List <HSLineItem>() { new HSLineItem() { Quantity = 1 } } }; var z_po = ZohoPurchaseOrderMapper.Map(z_order, oc_order, z_item, oc_lineitem.Items.ToList(), null, vendor.Items.FirstOrDefault()); var shipping_po = await _zoho.PurchaseOrders.ListAsync(new ZohoFilter() { Key = "purchaseorder_number", Value = $"{order.Order.ID}-{order.LineItems.FirstOrDefault()?.SupplierID} - 41000" }); if (shipping_po.Items.Any()) { z_po.purchaseorder_id = shipping_po.Items.FirstOrDefault()?.purchaseorder_id; list.Add(await _zoho.PurchaseOrders.SaveAsync(z_po)); } else { list.Add(await _zoho.PurchaseOrders.CreateAsync(z_po)); } } return(list); } catch (Exception ex) { return(new List <ZohoPurchaseOrder>()); } }