public virtual void LoadDataToGrid(SOImportProcess graph, OrdersParameters objOrderParams) { string integrationId = Filter.Current.IntegrationID == null ? objOrderParams.objSOAmazonSetup.IntegrationID : Filter.Current.IntegrationID; if (!SOHelper.CheckOrderExist(graph, integrationId, objOrderParams.objItem.AmazonOrderId)) { objOrderParams.processrecord = new SOProcessOrder(); objOrderParams.processrecord.ProcessID = objOrderParams.processID; objOrderParams.processrecord.AmazonOrderID = objOrderParams.objItem.AmazonOrderId; objOrderParams.processrecord.BuyerEmailID = objOrderParams.objItem.BuyerEmail; objOrderParams.processrecord.AmazonOrderDate = objOrderParams.objItem.PurchaseDate != null ? objOrderParams.objItem.PurchaseDate : (DateTime?)null; objOrderParams.processrecord.AmazonOrderLastUpdated = objOrderParams.objItem.LastUpdateDate != null ? objOrderParams.objItem.LastUpdateDate : (DateTime?)null; objOrderParams.processrecord.OrderAmount = objOrderParams.objItem.OrderTotal != null?Convert.ToDecimal(objOrderParams.objItem.OrderTotal.Amount) : 0m; objOrderParams.processrecord.AmazonStatus = objOrderParams.objItem.OrderStatus; objOrderParams.processrecord.SynDatetime = PX.Common.PXTimeZoneInfo.Now; objOrderParams.processrecord.IntegrationID = objOrderParams.integrationID; string xmlFeedContent = SOHelper.ListToXMLConverstion(objOrderParams.objItem); objOrderParams.processrecord.OrderSchema = xmlFeedContent; objOrderParams.processrecord.PrepareStatus = true; objOrderParams.processrecord.ImportStatus = false; graph.ImportOrderList.Cache.Insert(objOrderParams.processrecord); } }
public virtual void ImportAmazonRecords(SOImportProcess graph, List <SOProcessOrder> list, SOImportFilter currentFilter) { if (list.Count < 0) { return; } List <Order> amwOrder = null; List <OrderItem> amwLineItems = null; string amwOrderID = string.Empty; List <SOAmazonSetup> liSOAmazonSetup = new List <SOAmazonSetup>(); List <SOFieldMapping> liUsrMapping = new List <SOFieldMapping>(); SOAmazonSetup objamwSetup = null; SOOrderProcessLog objProcessLog = null; SOPartialMaint logGraph = PXGraph.CreateInstance <SOPartialMaint>(); if (currentFilter.ProcessAllTypes == true) { foreach (SOAmazonSetup objSetup in PXSelect <SOAmazonSetup, Where <SOAmazonSetup.status, Equal <True> > > .Select(graph)) { liSOAmazonSetup.Add(objSetup); } } else if (SOHelper.MarketplaceConfigurations(graph, currentFilter.IntegrationID, out objamwSetup)) { liSOAmazonSetup.Add(objamwSetup); } if (liSOAmazonSetup.Count > 0) { ARPaymentEntry docgraph = PXGraph.CreateInstance <ARPaymentEntry>(); SOOrderEntry orderEntry = PXGraph.CreateInstance <SOOrderEntry>(); orderEntry.RowUpdated.AddHandler <SOOrder>((sender, e) => { if (!sender.ObjectsEqual <SOOrder.orderDate>(e.Row, e.OldRow)) { SOOrder order = (SOOrder)e.Row; order.OrderDate = order.OrderDate.HasValue ? order.OrderDate.Value.Date : order.OrderDate; } }); InvokeServicesCallResponse objSyncOrderResponse = null; PrepareAndImportOrdersParams objScheduleParams = null; objProcessLog = new SOOrderProcessLog(); objProcessLog.ProcessDate = PX.Common.PXTimeZoneInfo.Now; objProcessLog.TotalRecordstoImport = list.Count; objProcessLog.Operation = SOConstants.btnImport; objProcessLog.ImportedRecordsCount = 0; objProcessLog.FailedRecordsCount = 0; bool isErrorOccured = false; List <string> liCarriers = PXSelect <Carrier> .Select(graph).RowCast <Carrier>().Select(c => c.CarrierID).ToList(); foreach (SOProcessOrder currentRecord in list) { try { orderEntry.Clear(); logGraph.Clear(); docgraph.Clear(); objProcessLog.IntegrationID = currentFilter.IntegrationID != null ? currentFilter.IntegrationID : currentRecord.IntegrationID; logGraph.OrderProcessLog.Insert(objProcessLog); logGraph.Actions.PressSave(); foreach (SOAmazonSetup objSOAmazonSetup in liSOAmazonSetup.Where(x => x.IntegrationID == currentRecord.IntegrationID)) { if (orderEntry.sosetup.Current != null) { if (!SOHelper.CheckOrderExist(graph, currentRecord.AmazonOrderID, currentRecord.IntegrationID)) { amwOrderID = currentRecord.AmazonOrderID; if (amwLineItems != null && amwLineItems.Count > 0) { amwLineItems.Clear(); } amwOrder = new List <Order>(); amwOrder.Add(SOHelper.SchemaDeserialization(graph, amwOrderID)); objServiceCallParams = new ServiceCallParameters(); objServiceCallParams.objSOAmazonSetup = objSOAmazonSetup; objServiceCallParams.amwOrderID = currentRecord.AmazonOrderID; objServiceCallParams.methodCall = SOConstants.invokeListOrderItems; objSyncOrderResponse = new InvokeServicesCallResponse(); objSyncOrderResponse = new SOOrdersServiceCall(clientOrder).InvokeServicesCalls(graph, objServiceCallParams); amwLineItems = objSyncOrderResponse != null && objSyncOrderResponse.objListOrderItemsResponse != null && objSyncOrderResponse.objListOrderItemsResponse.ListOrderItemsResult != null && objSyncOrderResponse.objListOrderItemsResponse.ListOrderItemsResult.OrderItems.Count > 0 ? objSyncOrderResponse.objListOrderItemsResponse.ListOrderItemsResult.OrderItems : amwLineItems; objScheduleParams = new PrepareAndImportOrdersParams(); objScheduleParams.objSOPartialMaint = logGraph; objScheduleParams.objSOAmazonSetup = objSOAmazonSetup; objScheduleParams.objSOOrderEntry = orderEntry; objScheduleParams.paymentGraph = docgraph; objScheduleParams.objSOProcessOrderRecord = currentRecord; objScheduleParams.ObjCurrentOrder = amwOrder[0]; objScheduleParams.objamwLineItems = amwLineItems; objScheduleParams.objliUsrMapping = liUsrMapping; objScheduleParams.listOfCarriers = liCarriers; objScheduleParams.CurrentOrderIndex = list.IndexOf(currentRecord); CreateSO.CreateSalesOrderandPayments(objScheduleParams); } else { isErrorOccured = true; SOLogService.LogImportStatus(objScheduleParams, true, SOMessages.recordAlreadyImported); PXProcessing <SOProcessOrder> .SetInfo(list.IndexOf(currentRecord), SOMessages.recordAlreadyImported); } } else { throw new PXException(SOMessages.configMissing); } } } catch (Exception ex) { isErrorOccured = true; SOLogService.LogImportStatus(objScheduleParams, false, ex.Message); PXProcessing <SOProcessOrder> .SetError(list.IndexOf(currentRecord), ex.Message); } } if (isErrorOccured) { throw new PXException(SOMessages.showErrorMsgOrders); } } }