private FulfillmentParent ShopifyOrderRecord(AcumaticaSoShipment salesOrderShipment) { var salesOrderRecord = salesOrderShipment.AcumaticaSalesOrder; var orderRecord = _syncOrderRepository.RetrieveSalesOrder(salesOrderRecord.AcumaticaOrderNbr); var shopifyOrderRecord = orderRecord.OriginalShopifyOrder(); var shopifyOrder = _shopifyJsonService.RetrieveOrder(shopifyOrderRecord.ShopifyOrderId); var shipment = salesOrderShipment.AcumaticaShipmentJson.DeserializeFromJson <Shipment>(); var location = RetrieveMatchingLocation(shipment); // Line Items // var details = shipment.DetailByOrder(orderRecord.AcumaticaOrderNbr); var fulfillment = new Fulfillment(); fulfillment.line_items = new List <LineItem>(); fulfillment.location_id = location.id; fulfillment.tracking_number = salesOrderShipment.AcumaticaTrackingNbr; // Build the Detail // foreach (var detail in details) { var stockItem = _syncInventoryRepository.RetrieveStockItem(detail.InventoryID.value); var variant = stockItem.MatchedVariant(); var shopifyLineItem = shopifyOrder.LineItem(variant.ShopifySku); var quantity = detail.ShippedQty.value; var fulfillmentDetail = new LineItem() { id = shopifyLineItem.id, quantity = (int)quantity, }; fulfillment.line_items.Add(fulfillmentDetail); } var parent = new FulfillmentParent() { fulfillment = fulfillment }; return(parent); }
public ValidationResult Validate(AcumaticaSoShipment shipmentRecord) { var output = new CreateFulfillmentValidation(); var salesOrder = shipmentRecord.AcumaticaSalesOrder; var shopifyOrderId = salesOrder.OriginalShopifyOrder().ShopifyOrderId; // Fulfilled in Shopify - thus corrupted! // output.AnyShopifyMadeFulfillments = _syncOrderRepository.AnyUnsyncedFulfillments(shopifyOrderId); // Unmatched Warehouse // var shipment = shipmentRecord.AcumaticaShipmentJson.DeserializeFromJson <Shipment>(); var warehouseRecord = _syncInventoryRepository.RetrieveWarehouse(shipment.WarehouseID.value); var locationRecord = warehouseRecord.MatchedLocation(); if (locationRecord == null) { output.WarehouseLocationUnmatched = true; } // Unmatched Stock Item/Inventory // foreach (var line in shipment.Details) { var stockItem = _syncInventoryRepository.RetrieveStockItem(line.InventoryID.value); var variant = stockItem.MatchedVariant(); if (variant == null) { output.UnmatchedVariantStockItems.Add(stockItem.ItemId); continue; } } // Error threshold // output.ErrorThresholdExceeded = salesOrder.OriginalShopifyOrder().ExceedsErrorLimit(); return(output.Result()); }
public void UpsertSoShipments(AcumaticaSalesOrder salesOrderRecord) { var salesOrder = _acumaticaJsonService.RetrieveSalesOrder(salesOrderRecord.AcumaticaOrderNbr); foreach (var shipment in salesOrder.Shipments) { var exists = _orderRepository.SoShipmentExists( salesOrderRecord.ShopifyOrderMonsterId, shipment.ShipmentNbr.value, shipment.InvoiceNbr.value); if (exists) { continue; } if (shipment.Status.value != SoShipmentStatus.Completed) { continue; } var record = new AcumaticaSoShipment(); record.AcumaticaSalesOrder = salesOrderRecord; record.AcumaticaShipmentNbr = shipment.ShipmentNbr.value; record.AcumaticaInvoiceNbr = shipment.InvoiceNbr.value; record.AcumaticaInvoiceType = shipment.InvoiceType.value; record.AcumaticaStatus = shipment.Status.value; record.AcumaticaShipmentJson = null; record.AcumaticaTrackingNbr = null; record.AcumaticaInvoiceAmount = null; record.AcumaticaInvoiceTax = null; record.NeedShipmentAndInvoiceGet = true; record.DateCreated = DateTime.UtcNow; record.LastUpdated = DateTime.UtcNow; _executionLogService.Log(LogBuilder.DetectedNewCompleteAcumaticaSoShipment(record)); _orderRepository.InsertSoShipmentInvoice(record); } }
private void PushFulfillmentToShopifyAux(AcumaticaSoShipment salesOrderShipment) { try { CorrectFulfillmentWithUnknownRef(salesOrderShipment.AcumaticaShipmentNbr); var syncReadiness = _fulfillmentStatusService.Validate(salesOrderShipment); if (syncReadiness.Success) { PushFulfillmentToShopify(salesOrderShipment.AcumaticaShipmentNbr); } } catch (Exception ex) { _pushLogger.Error(ex); _logService.Log($"Encounter error syncing {salesOrderShipment.LogDescriptor()}"); _syncOrderRepository .IncreaseOrderErrorCount(salesOrderShipment.AcumaticaSalesOrder.ShopifyOrder.ShopifyOrderId); throw; } }
public static string LogDescriptor(this AcumaticaSoShipment shipmentSalesOrderRef) { return($"Acumatica Shipment {shipmentSalesOrderRef.AcumaticaShipmentNbr}" + $" - Invoice {shipmentSalesOrderRef.AcumaticaInvoiceNbr}"); }
public void InsertSoShipmentInvoice(AcumaticaSoShipment record) { Entities.AcumaticaSoShipments.Add(record); Entities.SaveChanges(); }
public static string FillingUnknownShopifyFulfillmentRef( AcumaticaSoShipment shipmentRef, ShopifyFulfillment fulfillment) { return($"Filling unknown Shopify Fulfillment reference from {shipmentRef.LogDescriptor()} with {fulfillment.LogDescriptor()}"); }
public static string ShopifyFulfillmentWithUnknownRefTooManyMatches(AcumaticaSoShipment shipmentRef) { return($"{shipmentRef.LogDescriptor()} has a unknown Shopify Fulfillment reference and too many matches"); }
public static string ShopifyFulfillmentWithUnknownRefNoMatches(AcumaticaSoShipment shipmentRef) { return($"{shipmentRef.LogDescriptor()} has a unknown Shopify Fulfillment reference and no matches could be found"); }
public static string CreateShopifyFulfillment(AcumaticaSoShipment shipmentRef) { return($"Creating Shopify Fulfillment for {shipmentRef.LogDescriptor()}"); }
public static string DetectedNewCompleteAcumaticaSoShipment(AcumaticaSoShipment shipment) { return($"Detected new {shipment.LogDescriptor()} (Complete)"); }
public static bool HasSyncWithUnknownNbr(this AcumaticaSoShipment shipment) { return(shipment.ShopifyFulfillment != null && shipment.ShopifyFulfillment.ShopifyFulfillmentId == null); }
public static bool IsSynced(this AcumaticaSoShipment shipment) { return(shipment.ShopifyFulfillment != null && shipment.ShopifyFulfillment.ShopifyFulfillmentId.HasValue); }