コード例 #1
0
        private static void UpdateSubmitLogDetails(List <ProjectionShipmentDAC> list, SubmitFeedParamaters objSubmitFeedParams, ProjectionShipmentDAC currentRecord, AMSubmitFeedServiceCall.Result item)
        {
            objSubmitFeedParams.acmOrderNbr   = currentRecord.OrderNbr;
            objSubmitFeedParams.amazonOrderID = currentRecord.AmazonOrderID;
            objSubmitFeedParams.objSOAmazonSetup.IntegrationID = currentRecord.IntegrationID;
            objSubmitFeedParams.shipmentNbr  = currentRecord.ShipmentNbr;
            objSubmitFeedParams.shipmentType = currentRecord.ShipmentType;

            if (item != null)
            {
                objSubmitFeedParams.importOrderStatus = false;
                objSubmitFeedParams.xmlMessage        = item.ResultDescription;
                objSubmitFeedParams.feedMessage       = item.ResultDescription;
                PXProcessing <ProjectionShipmentDAC> .SetError(list.IndexOf(currentRecord), item.ResultDescription);
            }
            else
            {
                objSubmitFeedParams.importOrderStatus = true;
                objSubmitFeedParams.xmlMessage        = SOConstants.feedSubmitted;
                objSubmitFeedParams.feedMessage       = SOConstants.feedSubmitted;
                PXProcessing <ProjectionShipmentDAC> .SetInfo(list.IndexOf(currentRecord), SOConstants.feedSubmitted);
            }
            SOLogService.LogSubmitStatus(objSubmitFeedParams);
        }
コード例 #2
0
        public virtual void AmazonSubmitFeed(List <ProjectionShipmentDAC> list, SubmitFeedFilter currentFilter)
        {
            SOPartialMaint logGraph  = PXGraph.CreateInstance <SOPartialMaint>();
            int?           processId = list.Count > 0 ? SOLogService.LogSubmitCount(logGraph, currentFilter.IntegrationID, list.Count) : null;

            if (!(processId > 0))
            {
                return;
            }
            SubmitFeedParamaters objSubmitFeedParams = null;
            StringBuilder        sbXmlFeedData       = new StringBuilder();

            objEnvelope = new AmazonEnvelope();
            objHeader   = new Header();
            objHeader.DocumentVersion = SOConstants.documentVersion;
            objEnvelope.MessageType   = SOConstants.orderFulfillment;
            objEnvelope.Header        = objHeader;
            List <Message> liMsgContent       = new List <Message>();
            UTF8Encoding   encoding           = new UTF8Encoding();
            double         megaBytesLength    = 0.0d;
            bool           isErrorOccured     = false;
            Regex          xmlEmptytagsRemove = new Regex(@"(\s)*<(\w:\w|\w)*(\s)*/>");

            AMSubmitFeedServiceCall.AmazonEnvelope resAMEnv = null;
            List <Item> listItems = null;

            foreach (ProjectionShipmentDAC currentRecord in list)
            {
                SOAmazonSetup objSOAmazonSetup = null;
                Item          objitem          = null;
                SOHelper.MarketplaceConfigurations(logGraph, currentFilter.IntegrationID, out objSOAmazonSetup);
                objHeader.MerchantIdentifier = objSOAmazonSetup.SellerId;
                objSubmitFeedParams          = new SubmitFeedParamaters();
                listItems = new List <Item>();
                try
                {
                    logGraph.Clear();
                    foreach (PXResult <SOShipment, SOShipLine, Carrier, SOPackageDetail> result in PXSelectJoin <SOShipment, InnerJoin <SOShipLine, On <SOShipment.shipmentType, Equal <SOShipLine.shipmentType>,
                                                                                                                                                        And <SOShipment.shipmentNbr, Equal <SOShipLine.shipmentNbr> > >,
                                                                                                                                        InnerJoin <Carrier, On <SOShipment.shipVia, Equal <Carrier.carrierID> >,
                                                                                                                                                   LeftJoin <SOPackageDetail, On <SOPackageDetail.shipmentNbr, Equal <SOShipLine.shipmentNbr> > > > >,
                                                                                                                 Where <SOShipLine.shipmentNbr, Equal <Required <SOShipLine.shipmentNbr> > >,
                                                                                                                 OrderBy <Desc <SOPackageDetail.lineNbr> > > .Select(logGraph, currentRecord.ShipmentNbr))
                    {
                        SOShipment      objShipment       = (SOShipment)result;
                        SOShipLine      objShipLine       = (SOShipLine)result;
                        Carrier         objCarrier        = (Carrier)result;
                        SOPackageDetail objPackageDetails = (SOPackageDetail)result;
                        objitem = null;
                        if (objShipment != null && objShipLine != null && objPackageDetails != null && objPackageDetails.Confirmed != null && objPackageDetails.Confirmed == true && !string.IsNullOrEmpty(objPackageDetails.TrackNumber))
                        {
                            SOShipmentAmazonExt objShipmentExt = PXCache <SOShipment> .GetExtension <SOShipmentAmazonExt>(objShipment);

                            objSubmitFeedParams.soType       = objShipLine.OrigOrderType;
                            objSubmitFeedParams.acmOrderNbr  = objShipLine.OrigOrderNbr;
                            objSubmitFeedParams.shipmentType = objShipment.ShipmentType;
                            objSubmitFeedParams.shipmentNbr  = objShipment.ShipmentNbr;
                            objSubmitFeedParams.shipmentDate = objShipment.ShipDate;
                            objSubmitFeedParams.carrierCode  = !String.IsNullOrEmpty(objShipmentExt.UsrAmazonCarrierCode) ?
                                                               objShipmentExt.UsrAmazonCarrierCode : objShipment.ShipVia;
                            objSubmitFeedParams.shipVia = (objCarrier == null || String.IsNullOrEmpty(objCarrier.PluginMethod)) ?
                                                          objShipment.ShipVia : objCarrier.PluginMethod;
                            objSubmitFeedParams.trackingNbr = objPackageDetails.TrackNumber;
                            SOShipLineAmazonExt objShLineExt = objShipLine.GetExtension <SOShipLineAmazonExt>();
                            objSubmitFeedParams.amazonOrderID = objShLineExt != null && !string.IsNullOrEmpty(objShLineExt.UsrAmazonOrderID) ?
                                                                objShLineExt.UsrAmazonOrderID : string.Empty;
                            objitem = new Item();
                            objitem.AmazonOrderItemCode = objShLineExt != null && !string.IsNullOrEmpty(objShLineExt.UsrAMOrderItemID) ?
                                                          objShLineExt.UsrAMOrderItemID : string.Empty;
                            objitem.Quantity = objShipLine != null?Convert.ToInt32(objShipLine.ShippedQty) : 0;

                            listItems.Add(objitem);
                        }
                        else
                        {
                            throw new PXException(SOMessages.shipmentDetailsMissing);
                        }
                    }
                    objSubmitFeedParams.objPartialMaint     = logGraph;
                    objSubmitFeedParams.indexOfCurrentOrder = list.IndexOf(currentRecord);
                    objSubmitFeedParams.objSOAmazonSetup    = objSOAmazonSetup;
                    objSubmitFeedParams.processID           = processId;
                    if (listItems != null && listItems.Count > 0)
                    {
                        objSubmitFeedParams.liShipItem = listItems;
                    }
                    Message objMessage = GetListOfMessagesContent(objSubmitFeedParams);
                    if (objMessage.MessageID != null)
                    {
                        liMsgContent.Add(objMessage);
                    }
                }
                catch (Exception ex)
                {
                    isErrorOccured = true;
                    objSubmitFeedParams.feedMessage       = ex.Message;
                    objSubmitFeedParams.importOrderStatus = false;
                    objSubmitFeedParams.xmlMessage        = string.Empty;
                    SOLogService.LogSubmitStatus(objSubmitFeedParams);
                    PXProcessing <ProjectionShipmentDAC> .SetError(list.IndexOf(currentRecord), ex.Message);
                }
            }
            objEnvelope.MessageBody = SOConstants.messagebody;
            string resultFeed = SOHelper.ObjectToXMLConversion(objEnvelope, SOConstants.amazonEnvelope, false);

            if (liMsgContent.Count > 0)
            {
                foreach (Message listobj in liMsgContent)
                {
                    if (megaBytesLength >= SOConstants.feedSize)
                    {
                        break;
                    }
                    sbXmlFeedData.Append(SOHelper.ObjectToXMLConversion(listobj, SOConstants.messageBody, true) + SOConstants.getNewLine);
                    var byteData = encoding.GetBytes(sbXmlFeedData.ToString());
                    megaBytesLength = (byteData.Length / 1024f) / 1024f;
                }
                string xmlFeedContent = xmlEmptytagsRemove.Replace(resultFeed.Replace(SOConstants.msgbodyTag, Convert.ToString(sbXmlFeedData)), string.Empty);
                PXTrace.WriteInformation(xmlFeedContent);
                resAMEnv = new AMSubmitFeedServiceCall(clientFeed).InvokeServicesCalls(objSubmitFeedParams, xmlFeedContent);
            }
            if (resAMEnv != null && resAMEnv.Message != null && resAMEnv.Message.ProcessingReport != null && resAMEnv.Message.ProcessingReport.ProcessingSummary != null &&
                resAMEnv.Message.ProcessingReport.ProcessingSummary.MessagesProcessed == resAMEnv.Message.ProcessingReport.ProcessingSummary.MessagesSuccessful &&
                resAMEnv.Message.ProcessingReport.ProcessingSummary.MessagesWithError == 0)
            {
                foreach (ProjectionShipmentDAC currentRecord in list)
                {
                    UpdateSubmitLogDetails(list, objSubmitFeedParams, currentRecord, null);
                }
            }
            else if (resAMEnv != null && resAMEnv.Message != null && resAMEnv.Message.ProcessingReport != null &&
                     (resAMEnv.Message.ProcessingReport.ProcessingSummary.MessagesWithError > 0 ||
                      resAMEnv.Message.ProcessingReport.ProcessingSummary.MessagesSuccessful > 0))
            {
                bool isSubmitted;
                foreach (ProjectionShipmentDAC currentRecord in list)
                {
                    isSubmitted = false;
                    foreach (var item in resAMEnv.Message.ProcessingReport.Result.AsEnumerable().Where(x => x.MessageID == currentRecord.ShipmentNbr))
                    {
                        isSubmitted    = true;
                        isErrorOccured = true;
                        UpdateSubmitLogDetails(list, objSubmitFeedParams, currentRecord, item);
                    }
                    if (!isSubmitted)
                    {
                        UpdateSubmitLogDetails(list, objSubmitFeedParams, currentRecord, null);
                    }
                }
            }
            if (isErrorOccured)
            {
                throw new PXException(SOMessages.showErrorMsgFeeds);
            }
        }