public virtual void GetAmazonOrdersbyNextToken(SOScheduleProcess graph, PrepareAndImportOrdersParams objScheduleParams, ref bool isErrorOccured) { objSyncOrderResponse = new InvokeServicesCallResponse(); amwOrders = new List <Order>(); amwLineItems = new List <OrderItem>(); objServiceCallParams = new ServiceCallParameters(); objServiceCallParams.objSOAmazonSetup = objScheduleParams.objSOAmazonSetup; objServiceCallParams.amwOrderID = string.Empty; objServiceCallParams.methodCall = SOConstants.invokeListOrdersByNextToken; objServiceCallParams.fromDate = objScheduleParams.objSOPrepareAndImport.LastSyncDate; objServiceCallParams.toDate = objScheduleParams.objSOPrepareAndImport.ToDate; objServiceCallParams.nextToken = objScheduleParams.objNextToken; objSyncOrderResponse = new SOOrdersServiceCall(clientOrder).InvokeServicesCalls(graph, objServiceCallParams); if (objSyncOrderResponse != null && objSyncOrderResponse.objListOrdersByNextToken != null && objSyncOrderResponse.objListOrdersByNextToken.ListOrdersByNextTokenResult != null && objSyncOrderResponse.objListOrdersByNextToken.ListOrdersByNextTokenResult.Orders.Count > 0) { amwOrders = objSyncOrderResponse.objListOrdersByNextToken.ListOrdersByNextTokenResult.Orders.ToList(); objScheduleParams.amwOrders = amwOrders; SOHelper.PrepareRecord(graph, objScheduleParams, ref isErrorOccured); if (objSyncOrderResponse.objListOrdersByNextToken.ListOrdersByNextTokenResult.NextToken != null) { objScheduleParams.objNextToken = objSyncOrderResponse.objListOrdersByNextToken.ListOrdersByNextTokenResult.NextToken; GetAmazonOrdersbyNextToken(graph, objScheduleParams, ref isErrorOccured); } } }
private void SetSOHeaderObjectsData(PrepareAndImportOrdersParams orderParams) { SOOrder newOrder = new SOOrder(); if (orderParams.objSOOrderEntry.sosetup.Current != null) { SOSetupAmazonExt objSOOSetupext = orderParams.objSOOrderEntry.sosetup.Current.GetExtension <SOSetupAmazonExt>(); if (objSOOSetupext != null && objSOOSetupext.UsrGuestCustID.HasValue) { newOrder.OrderType = orderParams.objSOAmazonSetup.OrderType; newOrder = (SOOrder)orderParams.objSOOrderEntry.Document.Cache.Insert(newOrder); newOrder.CustomerID = objSOOSetupext.UsrGuestCustID; } else { throw new PXException(SOMessages.guestCustomerErrorMsg); } } AssignValueAsPerIntegrationMapping(orderParams.objliUsrMapping, newOrder, orderParams.ObjCurrentOrder, null, orderParams.objSOOrderEntry.Document.View.Name); newOrder.OrderDesc = !string.IsNullOrEmpty(orderParams.ObjCurrentOrder.FulfillmentChannel) ? orderParams.ObjCurrentOrder.FulfillmentChannel == SOConstants.fulfillmentChannelAFN ? string.IsNullOrEmpty(newOrder.OrderDesc) ? SOMessages.fbaOrder : newOrder.OrderDesc + " - " + SOMessages.fbaOrder : orderParams.ObjCurrentOrder.FulfillmentChannel == SOConstants.fulfillmentChannelMFN ? string.IsNullOrEmpty(newOrder.OrderDesc) ? SOMessages.fbmOrder : newOrder.OrderDesc + " - " + SOMessages.fbmOrder : newOrder.OrderDesc : newOrder.OrderDesc; newOrder.DefaultSiteID = orderParams.objSOAmazonSetup.DfltWarehouseID; SOOrderAmazonExt newOrderExt = newOrder.GetExtension <SOOrderAmazonExt>(); if (newOrderExt != null) { newOrderExt.UsrAmazonOrderID = orderParams.ObjCurrentOrder.AmazonOrderId; } orderParams.objSOOrderEntry.Document.Current = newOrder; orderParams.objSOOrderEntry.Document.Update(orderParams.objSOOrderEntry.Document.Current); }
private void SetFinancialInformationobjectsData(PrepareAndImportOrdersParams orderParams) { SOOrder financialInformation = (SOOrder)orderParams.objSOOrderEntry.Document.Current; if (financialInformation == null) { return; } if (orderParams.objSOOrderEntry.sosetup.Current != null) { bool isCarrierAvaliable = false; SOSetupAmazonExt objSOOSetupext = orderParams.objSOOrderEntry.sosetup.Current.GetExtension <SOSetupAmazonExt>(); if (orderParams != null && orderParams.objSOProcessOrderRecord != null && (orderParams.objSOProcessOrderRecord.Carrier != null || !string.IsNullOrEmpty(orderParams.objSOProcessOrderRecord.Carrier))) { isCarrierAvaliable = orderParams.listOfCarriers.Any(x => x.ToLower().Trim() == orderParams.objSOProcessOrderRecord.Carrier.ToLower().Trim()); } if (isCarrierAvaliable) { financialInformation.ShipVia = orderParams.objSOProcessOrderRecord.Carrier; } else if (objSOOSetupext != null && !string.IsNullOrEmpty(objSOOSetupext.UsrAmazonShipVia)) { financialInformation.ShipVia = objSOOSetupext.UsrAmazonShipVia; } orderParams.objSOOrderEntry.Document.Update(financialInformation); } AssignValueAsPerIntegrationMapping(orderParams.objliUsrMapping, financialInformation, orderParams.ObjCurrentOrder, null, /*SOConstants.currentDocument*/ orderParams.objSOOrderEntry.CurrentDocument.View.Name); orderParams.objSOOrderEntry.Document.Update(financialInformation); }
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); } }
private void SetFreightData(PrepareAndImportOrdersParams orderParams) { //Update Premium Freight SOOrder document = orderParams.objSOOrderEntry.Document.Current; SOOrderAmazonExt documentExt = PXCache <SOOrder> .GetExtension <SOOrderAmazonExt>(document); document.CuryPremiumFreightAmt = documentExt.UsrAmazonFreightTotal.GetValueOrDefault(0) - documentExt.UsrAmazonFreightDiscountTotal.GetValueOrDefault(0); orderParams.objSOOrderEntry.Document.Update(document); }
private void SetDocumentLevelDiscountandTaxData(PrepareAndImportOrdersParams orderParams) { if (taxtotal <= 0) { return; } SOOrder currentFin = (SOOrder)orderParams.objSOOrderEntry.Document.Current; if (currentFin != null && orderParams.objSOOrderEntry.sosetup.Current != null) { SOSetupAmazonExt objSOOSetupext = orderParams.objSOOrderEntry.sosetup.Current.GetExtension <SOSetupAmazonExt>(); if (objSOOSetupext != null && !string.IsNullOrEmpty(objSOOSetupext.UsrAmazonTaxID)) { if (currentFin.TaxZoneID != objSOOSetupext.UsrAmazonTaxZoneID) { currentFin.OverrideTaxZone = true; currentFin = orderParams.objSOOrderEntry.CurrentDocument.Update(currentFin); currentFin.TaxZoneID = objSOOSetupext.UsrAmazonTaxZoneID; currentFin = orderParams.objSOOrderEntry.CurrentDocument.Update(currentFin); } if (currentFin.TaxZoneID != objSOOSetupext.UsrAmazonTaxZoneID) { return; } SOTaxTran orderTax = (SOTaxTran)orderParams.objSOOrderEntry.Taxes.Select(); if (orderTax == null && !string.IsNullOrEmpty(objSOOSetupext.UsrAmazonTaxID)) { orderTax = (SOTaxTran)orderParams.objSOOrderEntry.Taxes.Cache.Insert(); orderTax.OrderType = orderParams.objSOOrderEntry.Document.Current.OrderType; orderTax.OrderNbr = orderParams.objSOOrderEntry.Document.Current.OrderNbr; orderTax.LineNbr = int.MaxValue; orderTax.TaxID = objSOOSetupext.UsrAmazonTaxID; orderParams.objSOOrderEntry.Taxes.Cache.Update(orderTax); orderTax.CuryTaxableAmt = taxableamount; orderTax.CuryTaxAmt = taxtotal; orderTax.TaxRate = taxRate; orderParams.objSOOrderEntry.Taxes.Cache.Update(orderTax); orderParams.objSOOrderEntry.Document.SetValueExt <SOOrder.curyTaxTotal>(orderParams.objSOOrderEntry.Document.Current, taxtotal); orderTotal = orderParams.objSOOrderEntry.Document.Current.OrderTotal + orderTax.CuryTaxAmt; orderParams.objSOOrderEntry.Document.SetValueExt <SOOrder.curyOrderTotal>(orderParams.objSOOrderEntry.Document.Current, orderTotal); orderParams.objSOOrderEntry.Document.Cache.Update(orderParams.objSOOrderEntry.Document.Current); } else if (orderTax != null && !string.IsNullOrEmpty(objSOOSetupext.UsrAmazonTaxID)) { orderTax.CuryTaxAmt = taxtotal; orderParams.objSOOrderEntry.Taxes.Cache.Update(orderTax); orderParams.objSOOrderEntry.Document.SetValueExt <SOOrder.curyTaxTotal>(orderParams.objSOOrderEntry.Document.Current, taxtotal); orderTotal = orderParams.objSOOrderEntry.Document.Current.OrderTotal + orderTax.CuryTaxAmt; orderParams.objSOOrderEntry.Document.SetValueExt <SOOrder.curyOrderTotal>(orderParams.objSOOrderEntry.Document.Current, orderTotal); orderParams.objSOOrderEntry.Document.Cache.Update(orderParams.objSOOrderEntry.Document.Current); } } } }
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; } }
private void SetShippingContactObjectsData(PrepareAndImportOrdersParams orderParams) { orderParams.objSOOrderEntry.Shipping_Contact.Current = (SOShippingContact)orderParams.objSOOrderEntry.Shipping_Contact.Select(); if (orderParams.objSOOrderEntry.Shipping_Contact.Current != null) { if (orderParams.objliUsrMapping.Where(x => (x.TargetObject == orderParams.objSOOrderEntry.Shipping_Contact.View.Name)).Count() > 0) { orderParams.objSOOrderEntry.Shipping_Contact.Current.OverrideContact = true; orderParams.objSOOrderEntry.Shipping_Contact.Update(orderParams.objSOOrderEntry.Shipping_Contact.Current); AssignValueAsPerIntegrationMapping(orderParams.objliUsrMapping, orderParams.objSOOrderEntry.Shipping_Contact.Current, orderParams.ObjCurrentOrder, null, orderParams.objSOOrderEntry.Shipping_Contact.View.Name); orderParams.objSOOrderEntry.Shipping_Contact.Update(orderParams.objSOOrderEntry.Shipping_Contact.Current); } } }
public void CreatePaymentProcess(PrepareAndImportOrdersParams orderParams) { SOOrder order = orderParams.objSOOrderEntry.Document.Current; SOOrderAmazonExt OrderExt = order.GetExtension <SOOrderAmazonExt>(); if (orderParams.objSOOrderEntry.sosetup.Current != null) { SOSetupAmazonExt objSOOSetupext = orderParams.objSOOrderEntry.sosetup.Current.GetExtension <SOSetupAmazonExt>(); if (objSOOSetupext != null && !string.IsNullOrEmpty(objSOOSetupext.UsrAmazonPaymentMethodID)) { string paymentType = ARPaymentType.Payment; orderParams.paymentGraph.Clear(); ARPayment payment = new ARPayment() { DocType = paymentType }; payment = PXCache <ARPayment> .CreateCopy(orderParams.paymentGraph.Document.Insert(payment)); payment.CustomerID = order.CustomerID; payment.CustomerLocationID = order.CustomerLocationID; payment.PaymentMethodID = objSOOSetupext.UsrAmazonPaymentMethodID; payment.PMInstanceID = order.PMInstanceID; payment.CuryOrigDocAmt = 0m; payment.ExtRefNbr = OrderExt != null ? OrderExt.UsrAmazonOrderID : order.OrderNbr; payment.DocDesc = order.OrderDesc; payment = orderParams.paymentGraph.Document.Update(payment); SOAdjust adj = new SOAdjust() { AdjdOrderType = order.OrderType.Trim(), AdjdOrderNbr = order.OrderNbr.Trim() }; orderParams.paymentGraph.SOAdjustments.Insert(adj); if (payment.CuryOrigDocAmt == 0m) { payment.CuryOrigDocAmt = payment.CurySOApplAmt; payment = orderParams.paymentGraph.Document.Update(payment); } orderParams.paymentGraph.Actions.PressSave(); if (orderParams.paymentGraph.Actions.Contains("Release")) { orderParams.paymentGraph.Actions["Release"].Press(); } } } }
private void SetShippingAddressObjectsData(PrepareAndImportOrdersParams orderParams) { orderParams.objSOOrderEntry.Shipping_Address.Current = (SOShippingAddress)orderParams.objSOOrderEntry.Shipping_Address.Select(); if (orderParams.objSOOrderEntry.Shipping_Address.Current != null) { if (orderParams.objliUsrMapping.Where(x => (x.TargetObject == orderParams.objSOOrderEntry.Shipping_Address.View.Name)).Count() > 0) { orderParams.objSOOrderEntry.Shipping_Address.Current.OverrideAddress = true; orderParams.objSOOrderEntry.Shipping_Address.Update(orderParams.objSOOrderEntry.Shipping_Address.Current); AssignValueAsPerIntegrationMapping(orderParams.objliUsrMapping, orderParams.objSOOrderEntry.Shipping_Address.Current, orderParams.ObjCurrentOrder, null, orderParams.objSOOrderEntry.Shipping_Address.View.Name); if (orderParams.objSOOrderEntry.Shipping_Address.Current.State != null) { orderParams.objSOOrderEntry.Shipping_Address.Current.State = SOHelper.GetStateID(orderParams.objSOOrderEntry, orderParams.objSOOrderEntry.Shipping_Address.Current.State, orderParams.objSOOrderEntry.Shipping_Address.Current.CountryID); } orderParams.objSOOrderEntry.Shipping_Address.Update(orderParams.objSOOrderEntry.Shipping_Address.Current); } } }
public static void LogImportStatus(PrepareAndImportOrdersParams orderParams, bool importOrderStatus, string errorlog) { if (orderParams != null && orderParams.objSOProcessOrderRecord != null) { UpdateImportStatus(orderParams.objSOPartialMaint, orderParams.objSOProcessOrderRecord, importOrderStatus); orderParams.objSOPartialMaint.Clear(); SOOrderLevelProcessLog logRecord = new SOOrderLevelProcessLog(); logRecord.IntegrationID = orderParams.objSOProcessOrderRecord.IntegrationID; logRecord.AmazonOrderID = orderParams.objSOProcessOrderRecord.AmazonOrderID; logRecord.ProcessID = orderParams.objSOProcessOrderRecord.ProcessID; logRecord.AcumaticaOrderType = orderParams.objSOOrderEntry.Document.Current != null ? orderParams.objSOOrderEntry.Document.Current.OrderType : null; logRecord.AcumaticaOrderID = orderParams.objSOOrderEntry.Document.Current != null ? orderParams.objSOOrderEntry.Document.Current.OrderNbr : null; logRecord.ImportStatus = importOrderStatus; logRecord.ErrorDesc = errorlog; orderParams.objSOPartialMaint.OrderLevelProcessLog.Current = logRecord; orderParams.objSOPartialMaint.OrderLevelProcessLog.Insert(orderParams.objSOPartialMaint.OrderLevelProcessLog.Current); orderParams.objSOPartialMaint.Actions.PressSave(); if (importOrderStatus) { RecordImported(orderParams.objSOPartialMaint, orderParams.objSOProcessOrderRecord, orderParams.objSOOrderEntry.Document.Current.OrderNbr, orderParams.objSOOrderEntry.Document.Current.OrderType); } } }
private void SetSOLineObjectsData(PrepareAndImportOrdersParams orderParams) { IEnumerable <SOFieldMapping> objMapping = orderParams.objliUsrMapping.Where(x => x.TargetObject == orderParams.objSOOrderEntry.Transactions.View.Name && x.TargetField.ToLower() == SOConstants.inventoryID.ToLower()); if (objMapping.ToList().Count > 0) { foreach (OrderItem currentitem in orderParams.objamwLineItems) { SOLine newitems = (SOLine)orderParams.objSOOrderEntry.Transactions.Cache.Insert(); foreach (SOFieldMapping data in orderParams.objliUsrMapping.Where(x => x.TargetObject == orderParams.objSOOrderEntry.Transactions.View.Name && x.TargetField.ToLower() == SOConstants.inventoryID.ToLower())) { if (data.SourceObject.ToLower().Trim() == SOConstants.orderItemTag.ToLower()) { string fieldValue = currentitem != null?Convert.ToString(currentitem.GetType().GetProperty(data.SourceField).GetValue(currentitem, null)) : string.Empty; string itemCode = SOLineInventoryItemAmazonExtAttribute.GetInventoryCode(orderParams.objSOOrderEntry.Transactions.Cache, fieldValue); InventoryItem item = PXSelect <InventoryItem, Where <InventoryItem.inventoryCD, Equal <Required <InventoryItem.inventoryCD> >, And <InventoryItem.itemStatus, Equal <InventoryItemStatus.active> > > > .Select(orderParams.objSOOrderEntry, itemCode); newitems.InventoryID = item != null && item.InventoryID.HasValue ? item.InventoryID : null; orderParams.objSOOrderEntry.Transactions.Update(newitems); if (newitems.InventoryID.HasValue) { AssignValueAsPerIntegrationMapping(orderParams.objliUsrMapping, newitems, orderParams.ObjCurrentOrder, currentitem, orderParams.objSOOrderEntry.Transactions.View.Name); //Embedd GiftPrice string sGiftWrappPrice = currentitem.GiftWrapPrice != null?Convert.ToString(currentitem.GiftWrapPrice.Amount) : string.Empty; newitems.CuryUnitPrice += String.IsNullOrEmpty(sGiftWrappPrice) ? 0m : Convert.ToDecimal(sGiftWrappPrice); newitems.CuryUnitPrice = newitems.CuryUnitPrice > 0 && currentitem.QuantityOrdered > 0 ? newitems.CuryUnitPrice / currentitem.QuantityOrdered : newitems.CuryUnitPrice; newitems.SiteID = orderParams.objSOAmazonSetup.DfltWarehouseID; SOSetupAmazonExt objSOOSetupext = orderParams.objSOOrderEntry.sosetup.Current.GetExtension <SOSetupAmazonExt>(); if (objSOOSetupext != null && !string.IsNullOrEmpty(objSOOSetupext.UsrAmazonTaxID)) { TaxCategoryDet objTaxDetails = PXSelect <TaxCategoryDet, Where <TaxCategoryDet.taxID, Equal <Required <Tax.taxID> > > > .Select(orderParams.objSOOrderEntry, objSOOSetupext.UsrAmazonTaxID); if (objTaxDetails != null) { newitems.TaxCategoryID = objTaxDetails.TaxCategoryID; } SOLineAmazonExt objnewitemsext = newitems.GetExtension <SOLineAmazonExt>(); if (objnewitemsext != null) { objnewitemsext.UsrAMOrderItemID = currentitem.OrderItemId; } orderParams.objSOOrderEntry.Transactions.Update(newitems); FillDiscountObjectsData(orderParams.objSOOrderEntry, newitems, currentitem); taxtotal += currentitem.GiftWrapTax != null && !string.IsNullOrEmpty(currentitem.GiftWrapTax.Amount) && Convert.ToDecimal(currentitem.GiftWrapTax.Amount) > 0 ? Convert.ToDecimal(currentitem.GiftWrapTax.Amount) : 0; taxtotal += currentitem.ItemTax != null && !string.IsNullOrEmpty(currentitem.ItemTax.Amount) && Convert.ToDecimal(currentitem.ItemTax.Amount) > 0 ? Convert.ToDecimal(currentitem.ItemTax.Amount) : 0; taxtotal += currentitem.ShippingTax != null && !string.IsNullOrEmpty(currentitem.ShippingTax.Amount) && Convert.ToDecimal(currentitem.ShippingTax.Amount) > 0 ? Convert.ToDecimal(currentitem.ShippingTax.Amount) : 0; taxableamount += currentitem.ItemPrice != null && !string.IsNullOrEmpty(currentitem.ItemPrice.Amount) && Convert.ToDecimal(currentitem.ItemPrice.Amount) > 0 ? Convert.ToDecimal(currentitem.ItemPrice.Amount) : 0; shippingprice += currentitem.ShippingPrice != null && !string.IsNullOrEmpty(currentitem.ShippingPrice.Amount) && Convert.ToDecimal(currentitem.ShippingPrice.Amount) > 0 ? Convert.ToDecimal(currentitem.ShippingPrice.Amount) : 0; taxRate = (taxableamount > 0) ? (taxtotal * 100) / taxableamount : 0; } else { throw new PXException(SOMessages.configMissing); } } else { throw new PXException(SOMessages.inventoryItemNotExists); } } else { throw new PXException(SOMessages.inventoryMappedtoOrderItem); } } } } else { throw new PXException(SOMessages.InvMappingErrorMsg); } }
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); } } }
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); } } }