private static void ApplyPayment(ARPaymentEntry graph, ARAutoApplyParameters filter, ARPayment payment, List <ARInvoice> arInvoiceList, List <ARRegister> toRelease)
        {
            if (arInvoiceList.Any() == false)
            {
                return;
            }

            int invoiceIndex = 0;
            var paymentsViewIntoInvoiceList = new List <ARInvoice>(arInvoiceList);

            graph.Clear();
            graph.Document.Current = payment;

            bool adjustmentAdded = false;

            while (graph.Document.Current.CuryUnappliedBal > 0 && invoiceIndex < paymentsViewIntoInvoiceList.Count)
            {
                if (graph.Document.Current.CuryApplAmt == null)
                {
                    object curyapplamt = graph.Document.Cache.GetValueExt <ARPayment.curyApplAmt>(graph.Document.Current);
                    if (curyapplamt is PXFieldState)
                    {
                        curyapplamt = ((PXFieldState)curyapplamt).Value;
                    }
                    graph.Document.Current.CuryApplAmt = (decimal?)curyapplamt;
                }
                graph.Document.Current.AdjDate        = filter.ApplicationDate;
                graph.Document.Current.AdjFinPeriodID = filter.FinPeriodID;
                graph.Document.Cache.Update(graph.Document.Current);

                ARInvoice invoice = paymentsViewIntoInvoiceList[invoiceIndex];

                ARAdjust adj = new ARAdjust();
                adj.AdjdDocType = invoice.DocType;
                adj.AdjdRefNbr  = invoice.RefNbr;

                graph.AutoPaymentApp = true;
                adj = graph.Adjustments.Insert(adj);
                if (adj == null)
                {
                    invoiceIndex++;
                    continue;
                }
                adjustmentAdded = true;
                if (adj.CuryDocBal <= 0m)
                {
                    arInvoiceList.Remove(invoice);
                }

                invoiceIndex++;
            }
            if (adjustmentAdded)
            {
                graph.Save.Press();
                if (filter.ReleaseBatchWhenFinished == true)
                {
                    toRelease.Add(graph.Document.Current);
                }
            }
        }
コード例 #2
0
        public static void ValidateCCPayment(PXGraph graph, List <IExternalTransaction> list, bool isMassProcess)
        {
            bool            failed          = false;
            ARCashSaleEntry arCashSaleGraph = null;
            ARPaymentEntry  arPaymentGraph  = null;
            SOInvoiceEntry  soInvoiceGraph  = null;

            for (int i = 0; i < list.Count; i++)
            {
                if (list[i] == null)
                {
                    continue;
                }

                if ((i % 100) == 0)
                {
                    if (arCashSaleGraph != null)
                    {
                        arCashSaleGraph.Clear();
                    }
                    if (arPaymentGraph != null)
                    {
                        arPaymentGraph.Clear();
                    }
                    if (soInvoiceGraph != null)
                    {
                        soInvoiceGraph.Clear();
                    }
                }

                IExternalTransaction tran = list[i];

                var resultSet = PXSelectJoin <Standalone.ARRegister,
                                              LeftJoin <ARPayment,
                                                        On <ARPayment.refNbr, Equal <Standalone.ARRegister.refNbr>,
                                                            And <ARPayment.docType, Equal <Standalone.ARRegister.docType> > >,
                                                        LeftJoin <ARInvoice,
                                                                  On <ARInvoice.refNbr, Equal <Standalone.ARRegister.refNbr>,
                                                                      And <ARInvoice.docType, Equal <Standalone.ARRegister.docType> > >,
                                                                  LeftJoin <SOInvoice,
                                                                            On <SOInvoice.refNbr, Equal <Standalone.ARRegister.refNbr>,
                                                                                And <SOInvoice.docType, Equal <Standalone.ARRegister.docType> > >,
                                                                            LeftJoin <Standalone.ARCashSale,
                                                                                      On <Standalone.ARCashSale.refNbr, Equal <Standalone.ARRegister.refNbr>,
                                                                                          And <Standalone.ARCashSale.docType, Equal <Standalone.ARRegister.docType> > > > > > >,
                                              Where <Standalone.ARRegister.refNbr, Equal <Required <Standalone.ARRegister.refNbr> >,
                                                     And <Standalone.ARRegister.docType, Equal <Required <Standalone.ARRegister.docType> > > > >
                                .SelectSingleBound(graph, null, tran.RefNbr, tran.DocType);

                foreach (PXResult <Standalone.ARRegister, ARPayment, ARInvoice, SOInvoice, Standalone.ARCashSale> arDoc in resultSet)
                {
                    if (arDoc == null)
                    {
                        continue;
                    }

                    try
                    {
                        if ((ARInvoice)arDoc is ARInvoice arInvoice &&
                            arInvoice != null && arInvoice.RefNbr != null)
                        {
                            if ((SOInvoice)arDoc is SOInvoice soInvoice &&
                                soInvoice != null && soInvoice.RefNbr != null)
                            {
                                soInvoiceGraph = soInvoiceGraph != null ? soInvoiceGraph : PXGraph.CreateInstance <SOInvoiceEntry>();
                                SOInvoiceEntry.PaymentTransaction ext = soInvoiceGraph.GetExtension <SOInvoiceEntry.PaymentTransaction>();
                                soInvoiceGraph.Document.Current   = arInvoice;
                                soInvoiceGraph.SODocument.Current = soInvoice;
                                if (ext.CanValidate(arInvoice))
                                {
                                    ext.validateCCPayment.Press();
                                }
                            }
                            else if ((Standalone.ARCashSale)arDoc is Standalone.ARCashSale arCashSale &&
                                     arCashSale != null && arCashSale.RefNbr != null)
                            {
                                arCashSaleGraph = arCashSaleGraph != null ? arCashSaleGraph : PXGraph.CreateInstance <ARCashSaleEntry>();
                                ARCashSaleEntry.PaymentTransaction ext = arCashSaleGraph.GetExtension <ARCashSaleEntry.PaymentTransaction>();
                                arCashSaleGraph.Document.Current = arCashSale;
                                if (ext.CanValidate(arCashSaleGraph.Document.Current))
                                {
                                    ext.validateCCPayment.Press();
                                }
                            }
                        }
コード例 #3
0
        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);
                }
            }
        }
コード例 #4
0
        private static void ApplyPayment(ARPaymentEntry graph, ARAutoApplyParameters filter, ARPayment payment, List <ARInvoice> arInvoiceList, List <ARRegister> toRelease, out string warningRefNbr)
        {
            warningRefNbr = String.Empty;

            if (arInvoiceList.Any() == false)
            {
                return;
            }

            if (payment.DocDate > filter.ApplicationDate)
            {
                warningRefNbr = payment.RefNbr;
                PXProcessing <ARStatementCycle> .SetWarning(Messages.FuturePaymentWarning);

                return;
            }

            int invoiceIndex = 0;
            var paymentsViewIntoInvoiceList = new List <ARInvoice>(arInvoiceList);

            graph.Clear();
            graph.Document.Current = payment;

            bool adjustmentAdded = false;

            while (graph.Document.Current.CuryUnappliedBal > 0 && invoiceIndex < paymentsViewIntoInvoiceList.Count)
            {
                if (graph.Document.Current.CuryApplAmt == null)
                {
                    object curyapplamt = graph.Document.Cache.GetValueExt <ARPayment.curyApplAmt>(graph.Document.Current);
                    if (curyapplamt is PXFieldState)
                    {
                        curyapplamt = ((PXFieldState)curyapplamt).Value;
                    }
                    graph.Document.Current.CuryApplAmt = (decimal?)curyapplamt;
                }
                graph.Document.Current.AdjDate = filter.ApplicationDate;

                FinPeriodIDAttribute.SetPeriodsByMaster <ARPayment.adjFinPeriodID>(graph.Document.Cache, graph.Document.Current, filter.FinPeriodID);

                graph.Document.Cache.Adjust <PX.Objects.AR.AROpenPeriodAttribute>().For <ARPayment.adjFinPeriodID>(atr => atr.RedefaultOnDateChanged = false);
                graph.Document.Cache.Update(graph.Document.Current);

                ARInvoice invoice = paymentsViewIntoInvoiceList[invoiceIndex];

                var trans = invoice.PaymentsByLinesAllowed == true
                                        ? PXSelect <ARTran,
                                                    Where <ARTran.tranType, Equal <Required <ARTran.tranType> >,
                                                           And <ARTran.refNbr, Equal <Required <ARTran.refNbr> > > > > .Select(graph, invoice.DocType, invoice.RefNbr)
                                        : new PXResultset <ARTran>()
                {
                    null
                };

                foreach (ARTran tran in trans)
                {
                    ARAdjust adj = new ARAdjust();
                    adj.AdjdDocType = invoice.DocType;
                    adj.AdjdRefNbr  = invoice.RefNbr;
                    adj.AdjdLineNbr = tran?.LineNbr ?? 0;

                    graph.AutoPaymentApp = true;
                    adj = graph.Adjustments.Insert(adj);

                    if (adj != null)
                    {
                        adjustmentAdded = true;
                        if (adj.CuryDocBal <= 0m)
                        {
                            arInvoiceList.Remove(invoice);
                        }
                    }
                }

                invoiceIndex++;
            }
            if (adjustmentAdded)
            {
                graph.Save.Press();
                if (filter.ReleaseBatchWhenFinished == true)
                {
                    toRelease.Add(graph.Document.Current);
                }
            }
        }
コード例 #5
0
        public static void Redirect(PXCache sender, CATran catran)
        {
            if (catran == null)
            {
                return;
            }
            if (catran.OrigTranType == CAAPARTranType.GLEntry)
            {
                JournalEntry graph = PXGraph.CreateInstance <JournalEntry>();
                graph.Clear();
                if (sender != null)
                {
                    sender.IsDirty = false;
                }
                graph.BatchModule.Current = PXSelect <Batch, Where <Batch.module, Equal <Required <Batch.module> >, And <Batch.batchNbr, Equal <Required <Batch.batchNbr> > > > > .Select(graph, catran.OrigModule, catran.OrigRefNbr);

                throw new PXRedirectRequiredException(graph, true, "Document")
                      {
                          Mode = PXBaseRedirectException.WindowMode.NewWindow
                      };
            }
            else if (catran.OrigModule == GL.BatchModule.AP && (catran.OrigTranType == AP.APDocType.QuickCheck || catran.OrigTranType == AP.APDocType.VoidQuickCheck))
            {
                APQuickCheckEntry graph = PXGraph.CreateInstance <APQuickCheckEntry>();
                graph.Clear();
                if (sender != null)
                {
                    sender.IsDirty = false;
                }
                graph.Document.Current = PXSelect <APQuickCheck, Where <APQuickCheck.refNbr, Equal <Required <APQuickCheck.refNbr> >,
                                                                        And <APQuickCheck.docType, Equal <Required <APQuickCheck.docType> > > > > .Select(graph, catran.OrigRefNbr, catran.OrigTranType);

                throw new PXRedirectRequiredException(graph, true, "Document")
                      {
                          Mode = PXBaseRedirectException.WindowMode.NewWindow
                      };
            }
            else if (catran.OrigModule == GL.BatchModule.AP && catran.OrigTranType == CATranType.CABatch)
            {
                CABatchEntry graph = PXGraph.CreateInstance <CABatchEntry>();
                graph.Clear();
                if (sender != null)
                {
                    sender.IsDirty = false;
                }
                graph.Document.Current = PXSelect <CABatch, Where <CABatch.batchNbr, Equal <Required <CATran.origRefNbr> > > > .Select(graph, catran.OrigRefNbr);

                throw new PXRedirectRequiredException(graph, true, "Document")
                      {
                          Mode = PXBaseRedirectException.WindowMode.NewWindow
                      };
            }
            else if (catran.OrigModule == GL.BatchModule.AP)
            {
                APPaymentEntry graph = PXGraph.CreateInstance <APPaymentEntry>();
                graph.Clear();
                if (sender != null)
                {
                    sender.IsDirty = false;
                }
                graph.Document.Current = (APPayment)PXSelect <APPayment, Where <APPayment.refNbr, Equal <Required <APPayment.refNbr> >,
                                                                                And <APPayment.docType, Equal <Required <APPayment.docType> > > > > .Select(graph, catran.OrigRefNbr, catran.OrigTranType);

                throw new PXRedirectRequiredException(graph, true, "Document")
                      {
                          Mode = PXBaseRedirectException.WindowMode.NewWindow
                      };
            }
            else if (catran.OrigModule == GL.BatchModule.AR && (catran.OrigTranType == ARDocType.CashSale || catran.OrigTranType == ARDocType.CashReturn))
            {
                ARCashSale document = (ARCashSale)PXSelect <ARCashSale, Where <ARCashSale.refNbr, Equal <Required <ARCashSale.refNbr> >,
                                                                               And <ARCashSale.docType, Equal <Required <ARCashSale.docType> > > > > .Select(sender.Graph, catran.OrigRefNbr, catran.OrigTranType);

                if (document.OrigModule == BatchModule.SO && document.Released == false)
                {
                    SO.SOInvoiceEntry graph = PXGraph.CreateInstance <SO.SOInvoiceEntry>();
                    graph.Clear();
                    sender.IsDirty = false;

                    graph.Document.Current = (ARInvoice)PXSelect <ARInvoice, Where <ARInvoice.refNbr, Equal <Required <ARInvoice.refNbr> >,
                                                                                    And <ARInvoice.docType, Equal <Required <ARInvoice.docType> > > > > .Select(sender.Graph, catran.OrigRefNbr, catran.OrigTranType);

                    throw new PXRedirectRequiredException(graph, true, "Document")
                          {
                              Mode = PXBaseRedirectException.WindowMode.NewWindow
                          };
                }
                else
                {
                    ARCashSaleEntry graph = PXGraph.CreateInstance <ARCashSaleEntry>();
                    graph.Clear();
                    if (sender != null)
                    {
                        sender.IsDirty = false;
                    }

                    graph.Document.Current = document;
                    throw new PXRedirectRequiredException(graph, true, "Document")
                          {
                              Mode = PXBaseRedirectException.WindowMode.NewWindow
                          };
                }
            }
            else if (catran.OrigModule == GL.BatchModule.AR)
            {
                ARPaymentEntry graph = PXGraph.CreateInstance <ARPaymentEntry>();
                graph.Clear();
                if (sender != null)
                {
                    sender.IsDirty = false;
                }
                graph.Document.Current = (ARPayment)PXSelect <ARPayment, Where <ARPayment.refNbr, Equal <Required <ARPayment.refNbr> >,
                                                                                And <ARPayment.docType, Equal <Required <ARPayment.docType> > > > > .Select(graph, catran.OrigRefNbr, catran.OrigTranType);

                throw new PXRedirectRequiredException(graph, true, "Document")
                      {
                          Mode = PXBaseRedirectException.WindowMode.NewWindow
                      };
            }
            else if (catran.OrigModule == GL.BatchModule.CA && catran.OrigTranType == CATranType.CAAdjustment)
            {
                CATranEntry graph = PXGraph.CreateInstance <CATranEntry>();
                graph.Clear();
                if (sender != null)
                {
                    sender.IsDirty = false;
                }
                graph.CAAdjRecords.Current = PXSelect <CAAdj, Where <CAAdj.tranID, Equal <Required <CAAdj.tranID> > > > .Select(graph, catran.TranID);

                throw new PXRedirectRequiredException(graph, true, "Document")
                      {
                          Mode = PXBaseRedirectException.WindowMode.NewWindow
                      };
            }
            else if (catran.OrigModule == GL.BatchModule.CA && catran.OrigTranType == CATranType.CATransferExp)
            {
                CATranEntry graph = PXGraph.CreateInstance <CATranEntry>();
                graph.Clear();
                if (sender != null)
                {
                    sender.IsDirty = false;
                }
                graph.CAAdjRecords.Current = PXSelect <CAAdj, Where <CAAdj.adjTranType, Equal <CAAPARTranType.cATransferExp>, And <CAAdj.transferNbr, Equal <Required <CATran.origRefNbr> > > > > .Select(graph, catran.OrigRefNbr);

                throw new PXRedirectRequiredException(graph, true, "Document")
                      {
                          Mode = PXBaseRedirectException.WindowMode.NewWindow
                      };
            }
            else if (catran.OrigModule == GL.BatchModule.CA)
            {
                if (catran.OrigTranType == CATranType.CADeposit || catran.OrigTranType == CATranType.CAVoidDeposit)
                {
                    CADepositEntry graph = PXGraph.CreateInstance <CADepositEntry>();
                    graph.Clear();
                    if (sender != null)
                    {
                        sender.IsDirty = false;
                    }
                    graph.Document.Current = PXSelect <CADeposit, Where <CADeposit.tranType, Equal <Required <CADeposit.tranType> >,
                                                                         And <CADeposit.refNbr, Equal <Required <CADeposit.refNbr> > > > >
                                             .Select(graph, catran.OrigTranType, catran.OrigRefNbr);

                    throw new PXRedirectRequiredException(graph, true, "Document")
                          {
                              Mode = PXBaseRedirectException.WindowMode.NewWindow
                          };
                }
                else
                {
                    CashTransferEntry graph = PXGraph.CreateInstance <CashTransferEntry>();
                    graph.Clear();
                    if (sender != null)
                    {
                        sender.IsDirty = false;
                    }
                    graph.Transfer.Current = PXSelect <CATransfer, Where <CATransfer.tranIDOut, Equal <Required <CATransfer.tranIDOut> >, Or <CATransfer.tranIDIn, Equal <Required <CATransfer.tranIDIn> > > > >
                                             .Select(graph, catran.TranID, catran.TranID);

                    throw new PXRedirectRequiredException(graph, true, "Document")
                          {
                              Mode = PXBaseRedirectException.WindowMode.NewWindow
                          };
                }
            }
        }
コード例 #6
0
        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);
            }
        }
コード例 #7
0
        public static void ProcessDoc(ARPaymentEntry graph, ARStatementCycle cycle, ARAutoApplyParameters filter)
        {
            List <ARRegister> toRelease = new List <ARRegister>();

            // Build Invoices List
            foreach (Customer customer in
                     PXSelect <Customer,
                               Where <Customer.statementCycleId, Equal <Required <Customer.statementCycleId> >,
                                      And <Match <Required <AccessInfo.userName> > > > >
                     .Select(graph, cycle.StatementCycleId, graph.Accessinfo.UserName))
            {
                List <ARInvoice> arInvoiceList = new List <ARInvoice>();

                foreach (ARInvoice invoice in
                         PXSelect <ARInvoice, Where <ARInvoice.customerID, Equal <Required <ARInvoice.customerID> >,
                                                     And <ARInvoice.released, Equal <boolTrue>,
                                                          And <ARInvoice.openDoc, Equal <boolTrue>,
                                                               And <Where <ARInvoice.docType, Equal <Required <ARInvoice.docType> >,
                                                                           Or <ARInvoice.docType, Equal <Required <ARInvoice.docType> >,
                                                                               Or <ARInvoice.docType, Equal <Required <ARInvoice.docType> > > > > > > > >,
                                   OrderBy <Asc <ARInvoice.dueDate> > >
                         .Select(graph,
                                 customer.BAccountID,
                                 ARDocType.Invoice,
                                 ARDocType.FinCharge,
                                 filter.ApplyCreditMemos == true ? ARDocType.DebitMemo : ARDocType.Invoice))
                {
                    arInvoiceList.Add(invoice);
                }

                arInvoiceList.Sort(new Comparison <ARInvoice>(delegate(ARInvoice a, ARInvoice b)
                {
                    if ((bool)graph.arsetup.Current.FinChargeFirst)
                    {
                        int aSortOrder = (a.DocType == ARDocType.FinCharge ? 0 : 1);
                        int bSortOrder = (b.DocType == ARDocType.FinCharge ? 0 : 1);
                        int ret        = ((IComparable)aSortOrder).CompareTo(bSortOrder);
                        if (ret != 0)
                        {
                            return(ret);
                        }
                    }

                    {
                        object aDueDate = a.DueDate;
                        object bDueDate = b.DueDate;
                        int ret         = ((IComparable)aDueDate).CompareTo(bDueDate);

                        return(ret);
                    }
                }
                                                              ));


                if (arInvoiceList.Count > 0)
                {
                    int invoiceIndex = 0;

                    // this foreach gets all payments [and CreditMemos if applyCreditMemos = true] sorted by docDate
                    foreach (ARPayment payment in
                             PXSelect <ARPayment,
                                       Where <ARPayment.customerID, Equal <Required <ARPayment.customerID> >,
                                              And <ARPayment.released, Equal <boolTrue>,
                                                   And <ARPayment.openDoc, Equal <boolTrue>,
                                                        And <Where <ARPayment.docType, Equal <Required <ARPayment.docType> >,
                                                                    Or <ARPayment.docType, Equal <Required <ARPayment.docType> > > > > > > >,
                                       OrderBy <Asc <ARPayment.docDate> > >
                             .Select(graph,
                                     customer.BAccountID,
                                     ARDocType.Payment,
                                     filter.ApplyCreditMemos == true ? ARDocType.CreditMemo : ARDocType.Payment))
                    {
                        graph.Clear();
                        graph.Document.Current = payment;

                        if (graph.Adjustments.Select().Count == 0)
                        {
                            bool adjustmentAdded = false;
                            while (graph.Document.Current.CuryUnappliedBal > 0)
                            {
                                if (graph.Document.Current.CuryApplAmt == null)
                                {
                                    object curyapplamt = graph.Document.Cache.GetValueExt <ARPayment.curyApplAmt>(graph.Document.Current);
                                    if (curyapplamt is PXFieldState)
                                    {
                                        curyapplamt = ((PXFieldState)curyapplamt).Value;
                                    }
                                    graph.Document.Current.CuryApplAmt = (decimal?)curyapplamt;
                                }
                                graph.Document.Current.AdjDate        = filter.ApplicationDate;
                                graph.Document.Current.AdjFinPeriodID = filter.FinPeriodID;
                                graph.Document.Cache.Update(graph.Document.Current);

                                ARInvoice invoice = arInvoiceList[invoiceIndex];

                                ARAdjust adj = new ARAdjust();
                                adj.AdjdDocType = invoice.DocType;
                                adj.AdjdRefNbr  = invoice.RefNbr;

                                graph.AutoPaymentApp = true;
                                adj = graph.Adjustments.Insert(adj);
                                if (adj == null)
                                {
                                    throw new PXException(PXMessages.LocalizeFormat(Messages.ErrorAutoApply, invoice.DocType, invoice.RefNbr, payment.DocType, payment.RefNbr));
                                }
                                adjustmentAdded = true;
                                if (adj.CuryDocBal <= 0m)
                                {
                                    invoiceIndex++;
                                }
                                if (invoiceIndex >= arInvoiceList.Count)
                                {
                                    break;
                                }
                            }
                            if (adjustmentAdded)
                            {
                                graph.Save.Press();
                                if (filter.ReleaseBatchWhenFinished == true)
                                {
                                    toRelease.Add(graph.Document.Current);
                                }
                            }
                        }
                        if (invoiceIndex >= arInvoiceList.Count)
                        {
                            break;
                        }
                    }
                }
            }

            if (toRelease.Count > 0)
            {
                ARDocumentRelease.ReleaseDoc(toRelease, false);
            }
        }