private static void UpdateImportStatus(SOPartialMaint logGraph, SOProcessOrder currentRecord, bool importOrderStatus)
        {
            logGraph.ProcessOrder.Current = currentRecord;
            logGraph.ProcessOrder.Current.ImportStatus = importOrderStatus;
            logGraph.ProcessOrder.Update(logGraph.ProcessOrder.Current);
            logGraph.Actions.PressSave();
            SOOrderProcessLog processupdatecount = logGraph.UpdateImportProcessLog.Select();

            if (processupdatecount == null)
            {
                return;
            }
            int?importCount = processupdatecount.TotalRecordstoImport;

            processupdatecount.TotalRecordstoImport = importCount;
            if (importOrderStatus)
            {
                processupdatecount.ImportedRecordsCount = processupdatecount.ImportedRecordsCount + 1;
            }
            else
            {
                processupdatecount.FailedRecordsCount = processupdatecount.FailedRecordsCount + 1;
            }
            processupdatecount.ParentProcessID = currentRecord.ProcessID;
            logGraph.UpdateImportProcessLog.Update(processupdatecount);
            logGraph.Actions.PressSave();
        }
        public static void LogImportCount(SOImportProcess.SOImportFilter currentimportcount, string integrationId, SOPartialMaint logGraph, int?processId, string screenAction, bool isNoOrdersPrepared)
        {
            SOOrderProcessLog processcount = null;

            switch (screenAction)
            {
            case SOConstants.importorders:
                processcount                      = new SOOrderProcessLog();
                processcount.ProcessDate          = PX.Common.PXTimeZoneInfo.Now;
                processcount.TotalRecordstoImport = isNoOrdersPrepared == true ? 0 : currentimportcount.TotalRecordsToImport;
                processcount.ImportedRecordsCount = currentimportcount.TotalImportedRecords;
                processcount.FailedRecordsCount   = currentimportcount.TotalFailedRecords;
                processcount.IntegrationID        = integrationId;
                processcount.Operation            = SOConstants.btnPrepare;
                logGraph.OrderProcessLog.Insert(processcount);
                logGraph.Actions.PressSave();
                logGraph.OrderProcessLog.Current.ParentProcessID = logGraph.OrderProcessLog.Current.ProcessID;
                logGraph.OrderProcessLog.Update(logGraph.OrderProcessLog.Current);
                logGraph.Actions.PressSave();
                break;

            case SOConstants.scheduleimportorders:
                processcount = PXSelectReadonly <SOOrderProcessLog, Where <SOOrderProcessLog.processID, Equal <Required <SOOrderProcessLog.processID> > > > .Select(logGraph, Convert.ToInt32(processId));

                if (processcount == null)
                {
                    processcount                      = new SOOrderProcessLog();
                    processcount.ProcessDate          = PX.Common.PXTimeZoneInfo.Now;
                    processcount.Operation            = SOConstants.btnPrepareAndImport;
                    processcount.TotalRecordstoImport = isNoOrdersPrepared == true ? 0 : 1;
                    processcount.ImportedRecordsCount = 0;
                    processcount.FailedRecordsCount   = 0;
                    processcount.IntegrationID        = integrationId;
                    logGraph.OrderProcessLog.Insert(processcount);
                    logGraph.Actions.PressSave();
                    logGraph.OrderProcessLog.Current.ParentProcessID = logGraph.OrderProcessLog.Current.ProcessID;
                    logGraph.OrderProcessLog.Update(logGraph.OrderProcessLog.Current);
                    logGraph.Actions.PressSave();
                }
                else
                {
                    processcount.ProcessDate          = PX.Common.PXTimeZoneInfo.Now;
                    processcount.TotalRecordstoImport = processcount.TotalRecordstoImport + 1;
                    logGraph.OrderProcessLog.Update(processcount);
                    logGraph.Actions.PressSave();
                }
                break;
            }
        }
Esempio n. 3
0
        private void LoadIntegrationsToPrepareAndImport(SOImportProcess.SOImportFilter row)
        {
            if (row != null)
            {
                SOOrderProcessLog getProcessId = PXSelectGroupBy <SOOrderProcessLog, Aggregate <Max <SOOrderProcessLog.processID> > > .Select(this);

                PXSelectBase <SOProcessOrder> objMaxOrder = new PXSelectGroupBy <SOProcessOrder, Where <SOProcessOrder.integrationID, Equal <Required <SOProcessOrder.integrationID> > >, Aggregate <Max <SOProcessOrder.synDatetime> > >(this);

                if (row.IntegrationID != null && row.ProcessAllTypes == true && row.LastSyncDate != null)
                {
                    throw new PXException(SOMessages.msgProcessError);
                }
                else
                {
                    SOPrepareAndImport processRecord = new SOPrepareAndImport();
                    prepareAndImport.Cache.Clear();
                    SOOrderEntry orderEntry = PXGraph.CreateInstance <SOOrderEntry>();
                    if (row.IntegrationID != null && row.ProcessAllTypes == false)
                    {
                        foreach (SOProcessOrder objLastOrder in objMaxOrder.Select(row.IntegrationID))
                        {
                            Filter.Cache.SetValue <SOImportProcess.SOImportFilter.lastSyncDate>(row, objLastOrder.SynDatetime ?? GetMaxOrderDate(orderEntry, row.IntegrationID));
                            processRecord.LastSyncDate  = GetMaxOrderDate(orderEntry, row.IntegrationID);
                            processRecord.ToDate        = Filter.Current.TODate;
                            processRecord.IntegrationID = row.IntegrationID;
                            processRecord.ProcessID     = (getProcessId != null && getProcessId.ProcessID != null) ? getProcessId.ProcessID + 1 : 1;
                            prepareAndImport.Cache.Insert(processRecord);
                        }
                    }
                    else if (string.IsNullOrEmpty(row.IntegrationID) && row.ProcessAllTypes == true)
                    {
                        int?processId = (getProcessId != null && getProcessId.ProcessID != null) ? getProcessId.ProcessID + 1 : 1;
                        foreach (SOAmazonSetup integrationrecord in PXSelectReadonly <SOAmazonSetup, Where <SOAmazonSetup.status, Equal <True> > > .Select(this))
                        {
                            processRecord.LastSyncDate  = GetMaxOrderDate(orderEntry, integrationrecord.IntegrationID);
                            processRecord.ToDate        = row.TODate;
                            processRecord.IntegrationID = integrationrecord.IntegrationID;
                            processRecord.ProcessID     = processId++;
                            prepareAndImport.Cache.Insert(processRecord);
                        }
                    }
                }
            }
        }
        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);
                }
            }
        }
Esempio n. 5
0
        internal static int?GetProcessID(PXGraph graph)
        {
            SOOrderProcessLog objProcess = PXSelectGroupBy <SOOrderProcessLog, Aggregate <Max <SOOrderProcessLog.processID> > > .Select(graph);

            return(objProcess != null && objProcess.ProcessID != null ? (objProcess.ProcessID + 1) : 1);
        }