示例#1
0
        public static void Ingest(this AcumaticaSalesOrder target, SalesOrder source)
        {
            target.AcumaticaOrderNbr   = source.OrderNbr.value;
            target.AcumaticaStatus     = source.Status.value;
            target.AcumaticaIsTaxValid = source.IsTaxValid.value;
            target.AcumaticaLineTotal  = (decimal)source.Totals.LineTotalAmount.value;
            target.AcumaticaFreight    = (decimal)source.Totals.Freight.value;
            target.AcumaticaTaxTotal   = (decimal)source.Totals.TaxTotal.value;
            target.AcumaticaOrderTotal = (decimal)source.OrderTotal.value;
            target.AcumaticaQtyTotal   = (int)source.OrderedQty.value;

            // TODO - verify this is correct?
            //
            // target.AcumaticaOrderQty = source.Details.Sum(x => x.OrderQty.value);
        }
示例#2
0
        private void CreateBlankSalesOrderRecord(long shopifyOrderId)
        {
            var shopifyRecord = _syncOrderRepository.RetrieveShopifyOrder(shopifyOrderId);

            var acumaticaRecord = new AcumaticaSalesOrder();

            acumaticaRecord.AcumaticaIsTaxValid = true;
            acumaticaRecord.AcumaticaStatus     = "N/A";
            acumaticaRecord.AcumaticaOrderNbr   = AcumaticaSyncConstants.BlankRefNbr;
            acumaticaRecord.ShopifyOrder        = shopifyRecord;
            acumaticaRecord.AcumaticaCustomer   = shopifyRecord.ShopifyCustomer.AcumaticaCustomer;
            acumaticaRecord.DateCreated         = DateTime.UtcNow;
            acumaticaRecord.LastUpdated         = DateTime.UtcNow;

            shopifyRecord.NeedsOrderPut = false;
            _syncOrderRepository.Entities.AcumaticaSalesOrders.Add(acumaticaRecord);
            _syncOrderRepository.SaveChanges();
        }
        public void PopulateSoShipments(AcumaticaSalesOrder salesOrderRecord)
        {
            var soShipments = _orderRepository.RetrieveSoShipments(salesOrderRecord.ShopifyOrderMonsterId);

            foreach (var soShipment in soShipments)
            {
                if (soShipment.NeedShipmentAndInvoiceGet == false)
                {
                    continue;
                }

                if (soShipment.AcumaticaShipmentJson.IsNullOrEmpty() ||
                    soShipment.AcumaticaTrackingNbr.IsNullOrEmpty())
                {
                    var shipmentJson = _shipmentClient.RetrieveShipment(soShipment.AcumaticaShipmentNbr);
                    var shipment     = shipmentJson.DeserializeFromJson <Shipment>();

                    var trackingNumber = shipment.Packages.FirstOrDefault()?.TrackingNbr.value;

                    soShipment.AcumaticaShipmentJson = shipmentJson;
                    soShipment.AcumaticaTrackingNbr  = trackingNumber.IsNullOrEmptyAlt(BlankTrackingNumber());

                    _orderRepository.SaveChanges();
                }

                if (soShipment.AcumaticaInvoiceAmount == null || soShipment.AcumaticaInvoiceTax == null)
                {
                    var invoiceJson =
                        _invoiceClient.RetrieveInvoiceAndTaxes(
                            soShipment.AcumaticaInvoiceNbr, soShipment.AcumaticaInvoiceType);

                    var invoice = invoiceJson.DeserializeFromJson <Invoice>();

                    soShipment.AcumaticaInvoiceAmount = (decimal)invoice.Amount.value;
                    soShipment.AcumaticaInvoiceTax    = (decimal)invoice.TaxTotal.value;
                    //TaxDetails.Sum(x => x.TaxAmount.value);

                    _orderRepository.SaveChanges();
                }

                soShipment.NeedShipmentAndInvoiceGet = false;
                _orderRepository.SaveChanges();
            }
        }
示例#4
0
        // Push Order
        //
        private void CreateSalesOrder(long shopifyOrderId)
        {
            var shopifyOrderRecord = _syncOrderRepository.RetrieveShopifyOrder(shopifyOrderId);
            var acumaticaCustomer  = PushNonExistentCustomer(shopifyOrderRecord);

            var logContent = LogBuilder.CreateAcumaticaSalesOrder(shopifyOrderRecord);

            _logService.Log(logContent);

            // Write the Sales Order to Acumatica
            //
            var salesOrder = BuildNewSalesOrder(shopifyOrderRecord, acumaticaCustomer);

            // Create the Sync record *first*
            //
            var newRecord = new AcumaticaSalesOrder();

            newRecord.ShopifyOrderMonsterId    = shopifyOrderRecord.MonsterId;
            newRecord.ShopifyCustomerMonsterId = acumaticaCustomer.ShopifyCustomerMonsterId;
            newRecord.DateCreated = DateTime.UtcNow;
            newRecord.LastUpdated = DateTime.UtcNow;
            _acumaticaOrderRepository.InsertSalesOrder(newRecord);

            // Write to Acumatica Sales Order API
            //
            var resultJson = _salesOrderClient.WriteSalesOrder(salesOrder.SerializeToJson(), Expand.Totals);
            var newOrder   = resultJson.ToSalesOrderObj();

            newRecord.Ingest(newOrder);

            if (!newRecord.AcumaticaIsTaxValid)
            {
                shopifyOrderRecord.NeedsOrderPut = true;
            }
            else
            {
                shopifyOrderRecord.NeedsOrderPut = false;
            }

            shopifyOrderRecord.ErrorCount = 0;
            _syncOrderRepository.SaveChanges();
        }
        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);
            }
        }
示例#6
0
 public static string LogDescriptor(this AcumaticaSalesOrder salesOrder)
 {
     return($"Acumatica Sales Order {salesOrder.AcumaticaOrderNbr}");
 }
示例#7
0
 public static ShopifyOrder OriginalShopifyOrder(this AcumaticaSalesOrder order)
 {
     return(order.ShopifyOrder);
 }
示例#8
0
 public void DeleteSalesOrder(AcumaticaSalesOrder order)
 {
     Entities.AcumaticaSalesOrders.Remove(order);
     Entities.SaveChanges();
 }
示例#9
0
 public void InsertSalesOrder(AcumaticaSalesOrder order)
 {
     Entities.AcumaticaSalesOrders.Add(order);
     Entities.SaveChanges();
 }
示例#10
0
 public static string DetectedUpdateAcumaticaOrder(AcumaticaSalesOrder order)
 {
     return($"Detected changes to {order.LogDescriptor()}");
 }
示例#11
0
 public static string FillingUnknownAcumaticaSalesOrderRef(ShopifyOrder order, AcumaticaSalesOrder salesOrder)
 {
     return($"Filling unknown Sales Order reference from {order.LogDescriptor()} with {salesOrder.LogDescriptor()}");
 }