public void LogProcessCount(int?processCount, string integrationId, SOPartialMaint logGraph) { Filter.Current.TotalImportedRecords = 0; Filter.Current.TotalRecordsToImport = processCount; Filter.Current.TotalFailedRecords = 0; Filter.Update(Filter.Current); SOLogService.LogImportCount(Filter.Current, integrationId, logGraph, null, SOConstants.importorders, false); }
public void PrepareAndImportAmazonRecords(SOScheduleProcess graph, List <SOPrepareAndImport> listOfPrepareAndImport) { objSyncOrderResponse = new InvokeServicesCallResponse(); amwOrders = new List <Order>(); amwLineItems = new List <OrderItem>(); SOAmazonSetup objSOAmazonSetup = null; SOPartialMaint logGraph = PXGraph.CreateInstance <SOPartialMaint>(); SOOrderEntry orderEntry = PXGraph.CreateInstance <SOOrderEntry>(); ARPaymentEntry paymentGraph = PXGraph.CreateInstance <ARPaymentEntry>(); bool isErrorOccured = false; DateTime? businessDateTime = PX.Common.PXTimeZoneInfo.Now; List <string> liCarriers = PXSelect <Carrier> .Select(graph).RowCast <Carrier>().Select(c => c.CarrierID).ToList(); try { SOSetupAmazonExt objSOOSetupext = orderEntry.sosetup.Current.GetExtension <SOSetupAmazonExt>(); if (SOHelper.IsSOPreferencesDetailsExist(orderEntry, objSOOSetupext)) { foreach (SOPrepareAndImport currentRecord in listOfPrepareAndImport) { objSOAmazonSetup = null; if (SOHelper.MarketplaceConfigurations(graph, currentRecord.IntegrationID, out objSOAmazonSetup)) { objSyncOrderResponse = objSyncOrderResponse != null ? null : objSyncOrderResponse; if (amwOrders != null && amwOrders.Count > 0) { amwOrders.Clear(); } if (amwLineItems != null && amwLineItems.Count > 0) { amwLineItems.Clear(); } orderEntry.Clear(); logGraph.Clear(); paymentGraph.Clear(); objServiceCallParams = new ServiceCallParameters(); objServiceCallParams.objSOAmazonSetup = objSOAmazonSetup; objServiceCallParams.amwOrderID = string.Empty; objServiceCallParams.methodCall = SOConstants.invokeListOrders; objServiceCallParams.fromDate = currentRecord.LastSyncDate; objServiceCallParams.toDate = currentRecord.ToDate; // Prepare action is invoked objSyncOrderResponse = new SOOrdersServiceCall(clientOrder).InvokeServicesCalls(graph, objServiceCallParams); if (amwLineItems != null && amwLineItems.Count > 0) { amwLineItems.Clear(); } if (objSyncOrderResponse != null && objSyncOrderResponse.objListOrderResponse != null && objSyncOrderResponse.objListOrderResponse.ListOrdersResult != null && objSyncOrderResponse.objListOrderResponse.ListOrdersResult.Orders != null && objSyncOrderResponse.objListOrderResponse.ListOrdersResult.Orders.Count > 0) { amwOrders = objSyncOrderResponse.objListOrderResponse.ListOrdersResult.Orders.ToList(); // Saving the prepare action response objScheduleParams = new PrepareAndImportOrdersParams(); objScheduleParams.objSOPrepareAndImport = currentRecord; objScheduleParams.objSOAmazonSetup = objSOAmazonSetup; objScheduleParams.objSOOrderEntry = orderEntry; objScheduleParams.objSOPartialMaint = logGraph; objScheduleParams.businessDateTime = businessDateTime; objScheduleParams.paymentGraph = paymentGraph; objScheduleParams.listOfCarriers = liCarriers; objScheduleParams.amwOrders = amwOrders; SOHelper.PrepareRecord(graph, objScheduleParams, ref isErrorOccured); if (objSyncOrderResponse.objListOrderResponse.ListOrdersResult.NextToken != null) { objScheduleParams.objNextToken = objSyncOrderResponse.objListOrderResponse.ListOrdersResult.NextToken; objScheduleParams.paymentGraph = paymentGraph; GetAmazonOrdersbyNextToken(graph, objScheduleParams, ref isErrorOccured); } } else { SOLogService.LogImportCount(null, currentRecord.IntegrationID, logGraph, currentRecord.ProcessID, SOConstants.scheduleimportorders, true); } } else { throw new PXException(SOMessages.apidetailsMissing); } } } else { throw new PXException(SOMessages.configMissing); } } catch (Exception ex) { SOLogService.LogImportStatus(objScheduleParams, false, ex.Message); throw new PXException(ex.Message); } }
internal static void PrepareRecord(SOScheduleProcess graph, PrepareAndImportOrdersParams objScheduleParams, ref bool isErrorOccured) { SOProcessOrder objprocessorder = null; foreach (Order currentOrder in objScheduleParams.amwOrders) { try { objScheduleParams.objSOOrderEntry.Clear(); objScheduleParams.objSOPartialMaint.Clear(); objScheduleParams.paymentGraph.Clear(); if (!CheckOrderExist(objScheduleParams.objSOOrderEntry, objScheduleParams.objSOPrepareAndImport.IntegrationID, currentOrder.AmazonOrderId)) { objprocessorder = new SOProcessOrder(); objprocessorder.ProcessID = objScheduleParams.objSOPrepareAndImport != null && objScheduleParams.objSOPrepareAndImport.ProcessID != null ? objScheduleParams.objSOPrepareAndImport.ProcessID : 1; objprocessorder.IntegrationID = objScheduleParams.objSOPrepareAndImport != null && objScheduleParams.objSOPrepareAndImport.IntegrationID != null ? objScheduleParams.objSOPrepareAndImport.IntegrationID : string.Empty; objprocessorder.AmazonOrderID = currentOrder.AmazonOrderId; objprocessorder.BuyerEmailID = currentOrder.BuyerEmail; objprocessorder.AmazonOrderDate = currentOrder.PurchaseDate != null ? currentOrder.PurchaseDate : (DateTime?)null; objprocessorder.AmazonOrderLastUpdated = currentOrder.LastUpdateDate != null ? currentOrder.LastUpdateDate : (DateTime?)null; objprocessorder.OrderAmount = (currentOrder.OrderTotal != null && currentOrder.OrderTotal.Amount != null) ? Convert.ToDecimal(currentOrder.OrderTotal.Amount) : 0m; objprocessorder.AmazonStatus = currentOrder.OrderStatus; objprocessorder.SynDatetime = objScheduleParams.businessDateTime; objprocessorder.PrepareStatus = true; objprocessorder.ImportStatus = false; string xmlFeedContent = ListToXMLConverstion(currentOrder); objprocessorder.OrderSchema = xmlFeedContent; objScheduleParams.objSOPartialMaint.ProcessOrder.Cache.Insert(objprocessorder); objScheduleParams.objSOPartialMaint.Actions.PressSave(); SOLogService.LogImportCount(null, objprocessorder.IntegrationID, objScheduleParams.objSOPartialMaint, objprocessorder.ProcessID, SOConstants.scheduleimportorders, false); SOProcessOrder processRecord = PXSelect <SOProcessOrder, Where <SOProcessOrder.integrationID, Equal <Required <SOProcessOrder.integrationID> >, And <SOProcessOrder.processID, Equal <Required <SOProcessOrder.processID> >, And <SOProcessOrder.amazonOrderID, Equal <Required <SOProcessOrder.amazonOrderID> > > > >, OrderBy <Desc <SOProcessOrder.lineNumber> > > .Select(objScheduleParams.objSOOrderEntry, objScheduleParams.objSOPrepareAndImport.IntegrationID, objScheduleParams.objSOPrepareAndImport.ProcessID, currentOrder.AmazonOrderId); objScheduleParams.amazonOrderID = objprocessorder.AmazonOrderID; objScheduleParams.ObjCurrentOrder = currentOrder; objScheduleParams.objSOProcessOrderRecord = processRecord; GetAmazonOrderItems(graph, objScheduleParams); } else { SOLogService.LogImportCount(null, objScheduleParams.objSOAmazonSetup.IntegrationID, objScheduleParams.objSOPartialMaint, objScheduleParams.objSOPrepareAndImport.ProcessID, SOConstants.scheduleimportorders, true); } } catch (Exception ex) { isErrorOccured = true; SOLogService.LogImportStatus(objScheduleParams, false, ex.Message); } } }