public virtual Batch ReverseBatchProc(Batch b, ReverseBatchProcDelegate baseMethod) { GLVoucher glVoucher = PXSelect <GLVoucher, Where <GLVoucher.refNoteID, Equal <Required <Batch.noteID> > > > .Select(Base, b.NoteID); if (glVoucher == null) { return(baseMethod(b)); } Batch batch; using (PXTransactionScope transactionScope = new PXTransactionScope()) { GLVoucherBatch glVoucherBatch = PXSelect <GLVoucherBatch, Where <GLVoucherBatch.voucherBatchNbr, Equal <Required <GLVoucher.voucherBatchNbr> > > > .Select(Base, glVoucher.VoucherBatchNbr); var contextValues = new Dictionary <string, string>(); contextValues.Add(typeof(GLVoucherBatch.workBookID).FullName, glVoucherBatch.WorkBookID); contextValues.Add(typeof(GLVoucherBatch.voucherBatchNbr).FullName, glVoucherBatch.VoucherBatchNbr); Base.contextValues = contextValues; batch = baseMethod(b); if (batch.AutoReverseCopy == true) { VoucherBatch.Current = glVoucherBatch; var copy = (GLVoucher)Voucher.Cache.CreateCopy(glVoucher); copy.DocType = batch.BatchType; copy.RefNbr = batch.BatchNbr; copy.RefNoteID = batch.NoteID; copy.LineNbr = null; copy = this.Voucher.Insert(copy); this.Voucher.Cache.Persist(PXDBOperation.Insert); this.VoucherBatch.Cache.Persist(PXDBOperation.Update); Guid?noteID = PXNoteAttribute.GetNoteID <Batch.noteID>(Base.BatchModule.Cache, batch); Base.Caches[typeof(Note)].Persist(PXDBOperation.Insert); } transactionScope.Complete(Base); } return(batch); }
protected virtual bool HasUnreleasedDetails(GLVoucherBatch batch) { foreach (PXResult <GLVoucher, AP.APRegister, AR.ARRegister, CAAdj, Batch> it in this.Details.Select(batch.WorkBookID, batch.VoucherBatchNbr)) { GLVoucher iVoucher = it; AP.APRegister iAPR = it; AR.ARRegister iARR = it; CAAdj iCAR = it; Batch iGL = it; switch (iVoucher.Module) { case GL.BatchModule.AP: if (iAPR == null || string.IsNullOrEmpty(iAPR.RefNbr)) { throw new PXException(GL.Messages.DocumentIsInvalidForVoucher, iVoucher.RefNbr, iVoucher.VoucherBatchNbr); } return(iAPR.Released != true); case GL.BatchModule.AR: if (iARR == null || string.IsNullOrEmpty(iARR.RefNbr)) { throw new PXException(GL.Messages.DocumentIsInvalidForVoucher, iVoucher.RefNbr, iVoucher.VoucherBatchNbr); } return(iARR.Released != true); case GL.BatchModule.CA: if (iCAR == null || string.IsNullOrEmpty(iCAR.AdjRefNbr)) { throw new PXException(GL.Messages.DocumentIsInvalidForVoucher, iVoucher.RefNbr, iVoucher.VoucherBatchNbr); } return(iCAR.Released != true); case GL.BatchModule.GL: if (iGL == null || string.IsNullOrEmpty(iGL.BatchNbr)) { throw new PXException(GL.Messages.DocumentIsInvalidForVoucher, iVoucher.RefNbr, iVoucher.VoucherBatchNbr); } return(iGL.Released != true); default: throw new PXException(GL.Messages.ModuleIsNotSupported, iVoucher.Module); } } return(false); }
protected virtual void GLVoucherBatch_RowDeleting(PXCache sender, PXRowDeletingEventArgs e) { GLVoucherBatch row = (GLVoucherBatch)e.Row; if (row.Released == true) { throw new PXException(Messages.BatchDeleteReleased); } GLVoucher detail = PXSelect <GLVoucher, Where <GLVoucher.workBookID, Equal <Required <GLVoucherBatch.workBookID> >, And <GLVoucher.voucherBatchNbr, Equal <Required <GLVoucherBatch.voucherBatchNbr> > > > > .Select(this, row.WorkBookID, row.VoucherBatchNbr); if (detail != null) { throw new PXException(Messages.BatchDeleteWithDocuments); } }
protected virtual void Batch_RowSelected(PXCache sender, PXRowSelectedEventArgs e, PXRowSelected bs) { if (bs != null) { bs(sender, e); } Batch row = e.Row as Batch; if (row == null) { return; } bool isWithinContext = Base.IsWithinContext; GLVoucher voucher = this.Voucher.Select(); GLVoucherBatch voucherBatch = this.VoucherBatch.Select(); PXCache voucherCache = this.Voucher.Cache; bool isDetached = (voucher == null); PXUIFieldAttribute.SetEnabled <GLVoucher.refNbr>(voucherCache, voucher, false); PXUIFieldAttribute.SetVisible <GLVoucher.refNbr>(voucherCache, voucher, !isDetached); PXUIFieldAttribute.SetEnabled <Batch.batchNbr>(sender, e.Row, !isWithinContext); this.SaveAndAdd.SetVisible(!isDetached && isWithinContext); this.SaveAndAdd.SetEnabled(!isDetached && isWithinContext); if (isWithinContext) { Base.release.SetVisible(false); Base.release.SetEnabled(false); Base.reverseBatch.SetVisible(false); Base.reverseBatch.SetEnabled(false); PXUIFieldAttribute.SetVisible <Batch.autoReverse>(sender, row, false); PXUIFieldAttribute.SetEnabled <Batch.autoReverse>(sender, row, false); } if (!isDetached) { Base.createSchedule.SetVisible(false); Base.createSchedule.SetEnabled(false); } PXUIFieldAttribute.SetVisible <GLVoucher.voucherBatchNbr>(Voucher.Cache, null, !isDetached && !isWithinContext); PXUIFieldAttribute.SetVisible <GLVoucher.workBookID>(Voucher.Cache, null, !isDetached && !isWithinContext); if (isWithinContext && !isDetached) { sender.AllowInsert = !(voucherBatch != null && voucherBatch.Released == true); } }
protected static void SetVoucherAsCurrent2(PXGraph target, GLVoucher voucher) { if (voucher != null) { if (voucher.Module == GL.BatchModule.AP) { if (voucher.DocType == AP.APDocType.Check || voucher.DocType == AP.APDocType.Prepayment) { (target as AP.APPaymentEntry).Document.Current = (target as AP.APPaymentEntry).Document.Search <AP.APPayment.refNbr, AP.APPayment.docType>(voucher.RefNbr, voucher.DocType); } else if (voucher.DocType == AP.APDocType.Invoice || voucher.DocType == AP.APDocType.CreditAdj || voucher.DocType == AP.APDocType.DebitAdj) { (target as AP.APInvoiceEntry).Document.Current = (target as AP.APInvoiceEntry).Document.Search <AP.APInvoice.refNbr, AP.APInvoice.docType>(voucher.RefNbr, voucher.DocType); } else if (voucher.DocType == AP.APDocType.QuickCheck) { (target as AP.APQuickCheckEntry).Document.Current = (target as AP.APQuickCheckEntry).Document.Search <AP.Standalone.APQuickCheck.refNbr>(voucher.RefNbr, voucher.DocType); } } else if (voucher.Module == GL.BatchModule.AR) { if (voucher.DocType == AR.ARDocType.Payment || voucher.DocType == AR.ARDocType.Prepayment) { (target as AR.ARPaymentEntry).Document.Current = (target as AR.ARPaymentEntry).Document.Search <AR.ARPayment.refNbr, AR.ARPayment.docType>(voucher.RefNbr, voucher.DocType); } else if (voucher.DocType == AR.ARDocType.Invoice || voucher.DocType == AR.ARDocType.CreditMemo || voucher.DocType == AR.ARDocType.DebitMemo) { (target as AR.ARInvoiceEntry).Document.Current = (target as AR.ARInvoiceEntry).Document.Search <AR.ARInvoice.refNbr, AR.ARInvoice.docType>(voucher.RefNbr, voucher.DocType); } else if (voucher.DocType == AR.ARDocType.CashSale) { (target as AR.ARCashSaleEntry).Document.Current = (target as AR.ARCashSaleEntry).Document.Search <AR.Standalone.ARCashSale.refNbr, AR.Standalone.ARCashSale.docType>(voucher.RefNbr, voucher.DocType); } } else if (voucher.Module == GL.BatchModule.CA && voucher.DocType == CA.CATranType.CAAdjustment) { (target as CA.CATranEntry).CAAdjRecords.Current = (target as CA.CATranEntry).CAAdjRecords.Search <CA.CAAdj.adjRefNbr, CA.CAAdj.adjTranType>(voucher.RefNbr, voucher.DocType); } else if (voucher.Module == GL.BatchModule.GL && voucher.DocType == GLTranType.GLEntry) { (target as GL.JournalEntry).BatchModule.Current = (target as GL.JournalEntry).BatchModule.Search <GL.Batch.refNbr, GL.Batch.batchType>(voucher.RefNbr, voucher.DocType); } } }
private void RedirectToBatch(GLVoucherBatch batch, GLVoucher voucher = null) { if (batch != null) { GLWorkBook wb = PXSelect <GLWorkBook, Where <GLWorkBook.workBookID, Equal <Required <GLWorkBook.workBookID> > > > .Select(this, batch.WorkBookID); if (wb == null || wb.VoucherEditScreen == null) { throw new PXException(Messages.GLWorkBookIsInvalidOrVoucherEditScreenIsNotConfiguredForIt, batch.WorkBookID); } PXGraph target = null; PXSiteMapNode sm = PXSiteMap.Provider.FindSiteMapNodeFromKey((Guid)wb.VoucherEditScreen); if (sm == null) { throw new PXException(Messages.CannotFindSitemapNode); } Type graphType = System.Web.Compilation.BuildManager.GetType(sm.GraphType, true); Type parentGraphType = GLWorkBookMaint.GetGraphByDocType(batch.Module, wb.DocType); if (parentGraphType != null && parentGraphType.IsAssignableFrom(graphType)) { target = PXGraph.CreateInstance(graphType); } else { throw new PXException(Messages.GLVoucherEditGraphMayNotBeAssignedToTheBasedDocumentGraph, graphType, parentGraphType); } if (voucher == null) { voucher = PXSelect <GLVoucher, Where <GLVoucher.workBookID, Equal <Required <GLVoucher.workBookID> >, And <GLVoucher.voucherBatchNbr, Equal <Required <GLVoucher.voucherBatchNbr> > > >, OrderBy <Desc <GLVoucher.refNbr> > > .Select(this, batch.WorkBookID, batch.VoucherBatchNbr); } else { voucher = PXSelect <GLVoucher, Where <GLVoucher.workBookID, Equal <Required <GLVoucher.workBookID> >, And <GLVoucher.voucherBatchNbr, Equal <Required <GLVoucher.voucherBatchNbr> >, And <GLVoucher.refNbr, Equal <Required <GLVoucher.refNbr> > > > >, OrderBy <Desc <GLVoucher.refNbr> > > .Select(this, batch.WorkBookID, batch.VoucherBatchNbr, voucher.RefNbr); } SetVoucherAsCurrent(target, voucher); throw new PXRedirectWithinContextException(this, target, Messages.VoucherEdit, typeof(GLVoucherBatch.workBookID), typeof(GLVoucherBatch.voucherBatchNbr)); } }
protected virtual void ReleaseBatchDetailsProc(GLVoucherBatch aBatch, List <Batch> toPost, Dictionary <Guid, CAMessage> errors) { int toProcessCount = 0; List <Guid> failed = new List <Guid>(); Dictionary <string, IList> processQueue = new Dictionary <string, IList>(); foreach (PXResult <GLVoucher, AP.APRegister, AR.ARRegister, CAAdj, Batch> it in this.Details.Select(aBatch.WorkBookID, aBatch.VoucherBatchNbr)) { GLVoucher iVoucher = it; Guid key = iVoucher.RefNoteID.Value; try { switch (iVoucher.Module) { case GL.BatchModule.AP: AP.APRegister iAPR = it; if (iAPR == null || String.IsNullOrEmpty(iAPR.RefNbr)) { throw new PXException(GL.Messages.DocumentIsInvalidForVoucher, iVoucher.RefNbr, iVoucher.VoucherBatchNbr); } if (iAPR.Released != true) { toProcessCount++; List <AP.APRegister> list = new List <AP.APRegister>(1); list.Add(iAPR); if (iAPR.Scheduled == true) { throw new PXException(Messages.CannotReleaseScheduled); } AP.APDocumentRelease.ReleaseDoc(list, false, false, toPost); } break; case GL.BatchModule.AR: AR.ARRegister iARR = it; if (iARR == null || String.IsNullOrEmpty(iARR.RefNbr)) { throw new PXException(GL.Messages.DocumentIsInvalidForVoucher, iVoucher.RefNbr, iVoucher.VoucherBatchNbr); } if (iARR.Released != true) { toProcessCount++; List <AR.ARRegister> list = new List <AR.ARRegister>(1); list.Add(iARR); if (iARR.Scheduled == true) { throw new PXException(Messages.CannotReleaseScheduled); } AR.ARDocumentRelease.ReleaseDoc(list, false, toPost, null); } break; case GL.BatchModule.CA: CAAdj iCAR = it; if (iCAR == null || String.IsNullOrEmpty(iCAR.AdjRefNbr)) { throw new PXException(GL.Messages.DocumentIsInvalidForVoucher, iVoucher.RefNbr, iVoucher.VoucherBatchNbr); } if (iCAR.Released != true) { toProcessCount++; CATrxRelease.ReleaseDoc <CAAdj>(iCAR, 0, toPost); } break; case GL.BatchModule.GL: Batch iGL = it; if (iGL == null || String.IsNullOrEmpty(iGL.BatchNbr)) { throw new PXException(GL.Messages.DocumentIsInvalidForVoucher, iVoucher.RefNbr, iVoucher.VoucherBatchNbr); } if (iGL.Released != true) { toProcessCount++; List <Batch> list = new List <Batch>(1); list.Add(iGL); if (iGL.Scheduled == true) { throw new PXException(Messages.CannotReleaseScheduled); } JournalEntry.ReleaseBatch(list, toPost); } break; default: throw new PXException(GL.Messages.ModuleIsNotSupported, iVoucher.Module); } } catch (Exception ex) { failed.Add(key); //prevent process from stoping on first error errors.Add(key, FormatError(ex)); } } if (failed.Count > 0) { throw new PXException(Messages.ReleasingOfSomeOfTheIncludedDocumentsFailed, failed.Count, toProcessCount); } }
protected virtual void SetVoucherAsCurrent(PXGraph target, GLVoucher voucher) { SetVoucherAsCurrent(this, target, voucher); }