public static void GetAmazonOrderItems(SOScheduleProcess graph, PrepareAndImportOrdersParams objScheduleParams) { List <SOFieldMapping> liUsrMapping = new List <SOFieldMapping>(); InvokeServicesCallResponse objSyncOrderResponse = new InvokeServicesCallResponse(); List <OrderItem> amwLineItems = new List <OrderItem>(); objScheduleParams.objSOOrderEntry.Clear(); objScheduleParams.objSOPartialMaint.Clear(); objSyncOrderResponse = new InvokeServicesCallResponse(); amwLineItems = new List <OrderItem>(); ServiceCallParameters objServiceCallParams = new ServiceCallParameters(); objServiceCallParams.objSOAmazonSetup = objScheduleParams.objSOAmazonSetup; objServiceCallParams.amwOrderID = objScheduleParams.amazonOrderID; objServiceCallParams.methodCall = SOConstants.invokeListOrderItems; 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; if (objScheduleParams.ObjCurrentOrder != null) { objScheduleParams.objamwLineItems = amwLineItems; objScheduleParams.objliUsrMapping = liUsrMapping; CreateSO.CreateSalesOrderandPayments(objScheduleParams); } }
public static void CreateSalesOrderandPayments(PrepareAndImportOrdersParams objParams) { try { using (PXTransactionScope ts = new PXTransactionScope()) { if (objParams.objliUsrMapping.Where(X => X.IntegrationID == objParams.objSOProcessOrderRecord.IntegrationID).Count() == 0) { objParams.objliUsrMapping.Clear(); objParams.objliUsrMapping = SOHelper.GetUsrFieldMapping(objParams.objSOOrderEntry, objParams.objSOProcessOrderRecord.IntegrationID); } if (objParams.objliUsrMapping.Count > 0) { CreateSO objCreateSO = new CreateSO(); objCreateSO.SetSOHeaderObjectsData(objParams); objCreateSO.SetSOLineObjectsData(objParams); objCreateSO.SetBillingContactObjectsData(objParams); objCreateSO.SetBillingAddressobjectsData(objParams); objCreateSO.SetFinancialInformationobjectsData(objParams); objCreateSO.SetShippingContactObjectsData(objParams); objCreateSO.SetShippingAddressObjectsData(objParams); objCreateSO.SetFreightData(objParams); objCreateSO.SetDocumentLevelDiscountandTaxData(objParams); //Validate order total - decimal dAmazonTotal = 0; Decimal.TryParse(objParams.ObjCurrentOrder.OrderTotal.Amount, out dAmazonTotal); if (dAmazonTotal != objParams.objSOOrderEntry.Document.Current.CuryOrderTotal.GetValueOrDefault(0)) { throw new PXException(SOMessages.ErrorOrderTotalNotMatch); } objParams.objSOOrderEntry.Actions.PressSave(); objCreateSO.CreatePaymentProcess(objParams); if (objParams.objSOOrderEntry.Document.Current != null && !string.IsNullOrEmpty(objParams.objSOOrderEntry.Document.Current.OrderNbr)) { ts.Complete(); SOLogService.LogImportStatus(objParams, true, SOMessages.sucess); PXProcessing <SOProcessOrder> .SetInfo(objParams.CurrentOrderIndex, SOMessages.sucess); } } else { throw new PXException(SOMessages.FieldMappingEmptyErrMsg); } } } catch (Exception ex) { throw ex; } }
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); } } }