protected virtual void prepareRecords() { List <string> importedRecords = new List <string>(); SOImportFilter currentFilter = Filter.Current; PXLongOperation.StartOperation(this, delegate() { SOOrderEntry orderEntry = PXGraph.CreateInstance <SOOrderEntry>(); SOImportProcess graph = PXGraph.CreateInstance <SOImportProcess>(); SOPartialMaint logGraph = PXGraph.CreateInstance <SOPartialMaint>(); if (currentFilter != null) { if ((string.IsNullOrEmpty(currentFilter.IntegrationID) && currentFilter.ProcessAllTypes == false) || (!string.IsNullOrEmpty(currentFilter.IntegrationID) && currentFilter.ProcessAllTypes == true)) { throw new PXException(SOMessages.validationIntegrationIdandprocessall); } if (currentFilter.TODate.Value.Date > graph.Accessinfo.BusinessDate.Value.Date) { throw new PXException(SOMessages.validationTodateandBusinessDate); } if (currentFilter.LastSyncDate > currentFilter.TODate) { throw new PXException(SOMessages.validationFromandTodate); } try { orderEntry.Clear(); SOSetupAmazonExt objSOOSetupext = orderEntry.sosetup.Current.GetExtension <SOSetupAmazonExt>(); if (SOHelper.IsSOPreferencesDetailsExist(orderEntry, objSOOSetupext)) { SOAmazonSetup objSOAmazonSetupDetails = null; objOrdersParameters = new OrdersParameters(); SOProcessOrder processrecord = null; int?processedCount = 0; bool isValidConfiguration = SOHelper.MarketplaceConfigurations(graph, currentFilter.IntegrationID, out objSOAmazonSetupDetails); // To Get the Max date & time if the same date is processed again //Dhiren-4/11/2019 - We need to revisit date range Delta logic. //SOProcessOrder objProcessOrder = new PXSelect<SOProcessOrder, Where<SOProcessOrder.integrationID, Equal<Required<SOProcessOrder.integrationID>>, // And<SOProcessOrder.amazonOrderDate, Between<Required<SOProcessOrder.amazonOrderDate>, Required<SOProcessOrder.amazonOrderDate>>>>, // OrderBy<Desc<SOProcessOrder.amazonOrderDate>>>(graph).SelectSingle(currentFilter.IntegrationID, currentFilter.LastSyncDate, currentFilter.TODate); //currentFilter.FromDate = objProcessOrder != null && objProcessOrder.AmazonOrderDate.HasValue ? objProcessOrder.AmazonOrderDate : currentFilter.LastSyncDate; currentFilter.FromDate = currentFilter.LastSyncDate; Filter.Cache.Update(currentFilter); if (currentFilter.IntegrationID != null && currentFilter.ProcessAllTypes == false) { if (isValidConfiguration) { int?processId = SOHelper.GetProcessID(graph); PrepareAllRecords(graph, importedRecords, currentFilter, out processrecord, objSOAmazonSetupDetails, processId, out processedCount, logGraph); if (processedCount > 0) { LogProcessCount(processedCount, currentFilter.IntegrationID, logGraph); } graph.Actions.PressSave(); } else { throw new PXException(SOMessages.apidetailsMissing); } } else if (string.IsNullOrEmpty(currentFilter.IntegrationID) && currentFilter.ProcessAllTypes == true) { ImportOrderList.Cache.Clear(); int?processId = SOHelper.GetProcessID(graph); foreach (SOAmazonSetup objSOAmazonSetup in PXSelectReadonly <SOAmazonSetup, Where <SOAmazonSetup.status, Equal <True> > > .Select(graph)) { try { PrepareAllRecords(graph, importedRecords, currentFilter, out processrecord, objSOAmazonSetup, processId, out processedCount, logGraph); if (processedCount > 0) { LogProcessCount(processedCount, objSOAmazonSetup.IntegrationID, logGraph); } processId++; graph.Actions.PressSave(); } catch (Exception ex) { throw new PXException(!string.IsNullOrEmpty(ex.Message) ? ex.Message : ex.InnerException != null && ex.InnerException.InnerException != null ? ex.InnerException.InnerException.Message : SOConstants.exceptionIsEmpty); } } } } else { throw new PXException(SOMessages.configMissing); } } catch (Exception ex) { throw new PXException(!string.IsNullOrEmpty(ex.Message) ? ex.Message : ex.InnerException != null && ex.InnerException.InnerException != null ? ex.InnerException.InnerException.Message : SOConstants.exceptionIsEmpty); } } }); }
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); } }