コード例 #1
0
        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);
        }
コード例 #2
0
        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());
        }
コード例 #3
0
        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);
            }
        }
コード例 #4
0
        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;
            }
        }
コード例 #5
0
ファイル: Descriptors.cs プロジェクト: stackthatcode/Monster
 public static string LogDescriptor(this AcumaticaSoShipment shipmentSalesOrderRef)
 {
     return($"Acumatica Shipment {shipmentSalesOrderRef.AcumaticaShipmentNbr}" +
            $" - Invoice {shipmentSalesOrderRef.AcumaticaInvoiceNbr}");
 }
コード例 #6
0
 public void InsertSoShipmentInvoice(AcumaticaSoShipment record)
 {
     Entities.AcumaticaSoShipments.Add(record);
     Entities.SaveChanges();
 }
コード例 #7
0
 public static string FillingUnknownShopifyFulfillmentRef(
     AcumaticaSoShipment shipmentRef, ShopifyFulfillment fulfillment)
 {
     return($"Filling unknown Shopify Fulfillment reference from {shipmentRef.LogDescriptor()} with {fulfillment.LogDescriptor()}");
 }
コード例 #8
0
 public static string ShopifyFulfillmentWithUnknownRefTooManyMatches(AcumaticaSoShipment shipmentRef)
 {
     return($"{shipmentRef.LogDescriptor()} has a unknown Shopify Fulfillment reference and too many matches");
 }
コード例 #9
0
 public static string ShopifyFulfillmentWithUnknownRefNoMatches(AcumaticaSoShipment shipmentRef)
 {
     return($"{shipmentRef.LogDescriptor()} has a unknown Shopify Fulfillment reference and no matches could be found");
 }
コード例 #10
0
 public static string CreateShopifyFulfillment(AcumaticaSoShipment shipmentRef)
 {
     return($"Creating Shopify Fulfillment for {shipmentRef.LogDescriptor()}");
 }
コード例 #11
0
 public static string DetectedNewCompleteAcumaticaSoShipment(AcumaticaSoShipment shipment)
 {
     return($"Detected new {shipment.LogDescriptor()} (Complete)");
 }
コード例 #12
0
 public static bool HasSyncWithUnknownNbr(this AcumaticaSoShipment shipment)
 {
     return(shipment.ShopifyFulfillment != null &&
            shipment.ShopifyFulfillment.ShopifyFulfillmentId == null);
 }
コード例 #13
0
 public static bool IsSynced(this AcumaticaSoShipment shipment)
 {
     return(shipment.ShopifyFulfillment != null &&
            shipment.ShopifyFulfillment.ShopifyFulfillmentId.HasValue);
 }