Esempio n. 1
0
        public virtual IEnumerable export(PXAdapter adapter)
        {
            CheckPrevOperation();
            CABatch document = this.Document.Current;

            if (document != null && document.Released == true && document.Hold == false)
            {
                PXResult <PaymentMethod, SYMapping> res = (PXResult <PaymentMethod, SYMapping>) PXSelectJoin <PaymentMethod,
                                                                                                              LeftJoin <SYMapping, On <SYMapping.mappingID, Equal <PaymentMethod.aPBatchExportSYMappingID> > >,
                                                                                                              Where <PaymentMethod.paymentMethodID, Equal <Optional <CABatch.paymentMethodID> > > > .Select(this, document.PaymentMethodID);

                PaymentMethod pt  = res;
                SYMapping     map = res;
                if (pt != null && pt.APCreateBatchPayment == true && pt.APBatchExportSYMappingID != null && map != null)
                {
                    string defaultFileName = this.GenerateFileName(document);
                    PXLongOperation.StartOperation(this, delegate()
                    {
                        PX.Api.SYExportProcess.RunScenario(map.Name,
                                                           SYMapping.RepeatingOption.All,
                                                           true,
                                                           true,
                                                           new PX.Api.PXSYParameter(ExportProviderParams.FileName, defaultFileName),
                                                           new PX.Api.PXSYParameter(ExportProviderParams.BatchNbr, document.BatchNbr));
                    });
                }
                else
                {
                    throw new PXException(Messages.CABatchExportProviderIsNotConfigured);
                }
            }
            return(adapter.Get());
        }
        protected virtual void CABatch_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
        {
            CABatch row = e.Row as CABatch;

            if (row == null)
            {
                return;
            }

            bool isReleased = (row.Released == true);

            PXUIFieldAttribute.SetEnabled(sender, row, false);
            PXUIFieldAttribute.SetEnabled <CABatch.batchNbr>(sender, row, true);

            bool isProcessing = row.Processing ?? false;

            PXUIFieldAttribute.SetEnabled <CABatch.processing>(sender, row, true);

            bool allowDelete = !isReleased;

            if (allowDelete)
            {
                allowDelete = !(this.ReleasedPayments.Select(row.BatchNbr).Count > 0);
            }
            sender.AllowDelete = allowDelete;

            CashAccount cashaccount  = (CashAccount)PXSelectorAttribute.Select <CABatch.cashAccountID>(sender, row);
            bool        clearEnabled = (row.Released != true) && (cashaccount != null) && (cashaccount.Reconcile == true);

            PXUIFieldAttribute.SetEnabled <CABatch.hold>(sender, row, !isReleased);
            PXUIFieldAttribute.SetEnabled <CABatch.tranDesc>(sender, row, !isReleased);
            PXUIFieldAttribute.SetEnabled <CABatch.tranDate>(sender, row, !isReleased);
            PXUIFieldAttribute.SetEnabled <CABatch.batchSeqNbr>(sender, row, !isReleased);
            PXUIFieldAttribute.SetEnabled <CABatch.extRefNbr>(sender, row, !isReleased);

            if (!isReleased)
            {
                bool hasDetails = this.BatchPayments.Select().Count > 0;
                PXUIFieldAttribute.SetEnabled <CABatch.paymentMethodID>(sender, row, !hasDetails);
                PXUIFieldAttribute.SetEnabled <CABatch.cashAccountID>(sender, row, !hasDetails);
                if (hasDetails)
                {
                    decimal?curyTotal = decimal.Zero,
                           total      = decimal.Zero;
                    this.CalcDetailsTotal(ref curyTotal, ref total);
                    row.DetailTotal     = total;
                    row.CuryDetailTotal = curyTotal;
                }
            }
            PXUIFieldAttribute.SetEnabled <CABatch.exportFileName>(sender, row, isProcessing);
            PXUIFieldAttribute.SetEnabled <CABatch.exportTime>(sender, row, isProcessing);
            PXUIFieldAttribute.SetVisible <CABatch.dateSeqNbr>(sender, row, isReleased);

            this.Release.SetEnabled(!isReleased && (row.Hold == false));
            this.Export.SetEnabled(isReleased);
        }
Esempio n. 3
0
        public virtual IEnumerable release(PXAdapter adapter)
        {
            CheckPrevOperation();
            Save.Press();
            CABatch document = this.Document.Current;

            PXLongOperation.StartOperation(this, delegate() { CABatchEntry.ReleaseDoc(document); });

            return(adapter.Get());
        }
Esempio n. 4
0
        public virtual string GenerateFileName(CABatch aBatch)
        {
            if (aBatch.CashAccountID != null && !string.IsNullOrEmpty(aBatch.PaymentMethodID))
            {
                CashAccount acct = PXSelect <CashAccount, Where <CashAccount.cashAccountID, Equal <Required <CashAccount.cashAccountID> > > > .Select(this, aBatch.CashAccountID);

                if (acct != null)
                {
                    return(string.Format(Messages.CABatchDefaultExportFilenameTemplate, aBatch.PaymentMethodID, acct.CashAccountCD, aBatch.TranDate.Value, aBatch.DateSeqNbr));
                }
            }
            return(string.Empty);
        }
        public virtual IEnumerable release(PXAdapter adapter)
        {
            if (PXLongOperation.Exists(UID))
            {
                throw new ApplicationException(GL.Messages.PrevOperationNotCompleteYet);
            }
            Save.Press();
            CABatch document = this.Document.Current;

            PXLongOperation.StartOperation(this, delegate() { CABatchEntry.ReleaseDoc(document); });

            return(adapter.Get());
        }
Esempio n. 6
0
        private CABatch UpdateDocAmount(CABatchDetail row, bool negative)
        {
            CABatch document = this.Document.Current;

            if (row.OrigDocType != null && row.OrigRefNbr != null)
            {
                decimal?curyAmount = null, amount = null;
                if (row.OrigModule == GL.BatchModule.AP)
                {
                    APPayment payment = PXSelect <APPayment,
                                                  Where <APPayment.docType, Equal <Required <APPayment.docType> >,
                                                         And <APPayment.refNbr, Equal <Required <APPayment.refNbr> > > > > .Select(this, row.OrigDocType, row.OrigRefNbr);

                    if (payment != null)
                    {
                        curyAmount = payment.CuryOrigDocAmt;
                        amount     = payment.OrigDocAmt;
                    }
                }
                else
                {
                    ARPayment payment = PXSelect <ARPayment,
                                                  Where <ARPayment.docType, Equal <Required <ARPayment.docType> >,
                                                         And <ARPayment.refNbr, Equal <Required <ARPayment.refNbr> > > > > .Select(this, row.OrigDocType, row.OrigRefNbr);

                    if (payment != null)
                    {
                        curyAmount = payment.CuryOrigDocAmt;
                        amount     = payment.OrigDocAmt;
                    }
                }

                CABatch copy = (CABatch)this.Document.Cache.CreateCopy(document);

                if (curyAmount.HasValue)
                {
                    document.CuryDetailTotal += negative ? -curyAmount : curyAmount;
                }

                if (amount.HasValue)
                {
                    document.DetailTotal += negative ? -amount : amount;
                }

                document = this.Document.Update(document);
            }
            return(document);
        }
Esempio n. 7
0
            public virtual void RecalcTotals()
            {
                CABatch row = this.Document.Current;

                if (row != null)
                {
                    row.DetailTotal = row.CuryDetailTotal = row.Total = decimal.Zero;
                    foreach (PXResult <APPayment, CABatchDetail> item in this.APPaymentList.Select())
                    {
                        APPayment payment = item;
                        if (!string.IsNullOrEmpty(payment.RefNbr))
                        {
                            row.CuryDetailTotal += payment.CuryOrigDocAmt;
                            row.DetailTotal     += payment.OrigDocAmt;
                        }
                    }
                }
            }
        protected virtual void CABatch_CashAccountID_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
        {
            CABatch row = (CABatch)e.Row;

            row.Cleared   = false;
            row.ClearDate = null;
            if (cashAccount.Current == null || cashAccount.Current.CashAccountID != row.CashAccountID)
            {
                cashAccount.Current = (CashAccount)PXSelectorAttribute.Select <CABatch.cashAccountID>(sender, row);
            }
            if (cashAccount.Current.Reconcile != true)
            {
                row.Cleared   = true;
                row.ClearDate = row.TranDate;
            }
            sender.SetDefaultExt <CABatch.referenceID>(e.Row);
            sender.SetDefaultExt <CABatch.paymentMethodID>(e.Row);
        }
Esempio n. 9
0
        public static short GetNextDateSeqNbr(PXGraph graph, CABatch aDocument)
        {
            short   result      = 0;
            CABatch lastCABatch = PXSelectReadonly <CABatch,
                                                    Where <CABatch.cashAccountID, Equal <Required <CABatch.cashAccountID> >,
                                                           And <CABatch.paymentMethodID, Equal <Required <CABatch.paymentMethodID> >,
                                                                And <CABatch.released, Equal <True>,
                                                                     And <CABatch.tranDate, Equal <Required <CABatch.tranDate> > > > > >,
                                                    OrderBy <Desc <CABatch.dateSeqNbr> > > .Select(graph, aDocument.CashAccountID, aDocument.PaymentMethodID, aDocument.TranDate);

            if (lastCABatch != null)
            {
                result = lastCABatch.DateSeqNbr ?? (short)0;
                if (result >= short.MaxValue || result < short.MinValue)
                {
                    throw new PXException(Messages.DateSeqNumberIsOutOfRange);
                }
                result++;
            }
            return(result);
        }
Esempio n. 10
0
        public static void ReleaseDoc(CABatch aDocument)
        {
            if ((bool)aDocument.Released || (bool)aDocument.Hold)
            {
                throw new PXException(Messages.CABatchStatusIsNotValidForProcessing);
            }

            CABatchUpdate batchEntry = PXGraph.CreateInstance <CABatchUpdate>();
            CABatch       document   = batchEntry.Document.Select(aDocument.BatchNbr);

            batchEntry.Document.Current = document;

            if ((bool)document.Released || (bool)document.Hold)
            {
                throw new PXException(Messages.CABatchStatusIsNotValidForProcessing);
            }

            APRegister voided = PXSelectReadonly2 <APRegister,
                                                   InnerJoin <CABatchDetail, On <CABatchDetail.origModule, Equal <GL.BatchModule.moduleAP>,
                                                                                 And <CABatchDetail.origDocType, Equal <APRegister.docType>,
                                                                                      And <CABatchDetail.origRefNbr, Equal <APRegister.refNbr> > > > >,
                                                   Where <CABatchDetail.batchNbr, Equal <Required <CABatch.batchNbr> >,
                                                          And <APRegister.voided, Equal <True> > > > .Select(batchEntry, document.BatchNbr);

            if (voided != null && string.IsNullOrEmpty(voided.RefNbr) == false)
            {
                throw new PXException(Messages.CABatchContainsVoidedPaymentsAndConnotBeReleased);
            }

            List <APRegister>        unreleasedList   = new List <APRegister>();
            PXSelectBase <APPayment> selectUnreleased = new PXSelectReadonly2 <APPayment,
                                                                               InnerJoin <CABatchDetail,
                                                                                          On <CABatchDetail.origModule, Equal <GL.BatchModule.moduleAP>,
                                                                                              And <CABatchDetail.origDocType, Equal <APPayment.docType>,
                                                                                                   And <CABatchDetail.origRefNbr, Equal <APPayment.refNbr> > > > >,
                                                                               Where <CABatchDetail.batchNbr, Equal <Optional <CABatch.batchNbr> >,
                                                                                      And <APPayment.released, Equal <boolFalse> > > >(batchEntry);

            foreach (APPayment item in selectUnreleased.Select(document.BatchNbr))
            {
                if (item.Released != true)
                {
                    unreleasedList.Add(item);
                }
            }

            if (unreleasedList.Count > 0)
            {
                APDocumentRelease.ReleaseDoc(unreleasedList, true);
            }

            selectUnreleased.View.Clear();

            APPayment payment = selectUnreleased.Select(document.BatchNbr);

            if (payment != null)
            {
                throw new PXException(Messages.CABatchContainsUnreleasedPaymentsAndCannotBeReleased);
            }

            document.Released   = true;
            document.DateSeqNbr = GetNextDateSeqNbr(batchEntry, aDocument);
            batchEntry.RecalcTotals();
            document = batchEntry.Document.Update(document);
            batchEntry.Actions.PressSave();
        }
Esempio n. 11
0
        protected virtual void CABatch_PaymentMethodID_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
        {
            CABatch row = (CABatch)e.Row;

            sender.SetDefaultExt <CABatch.batchSeqNbr>(e.Row);
        }