Example #1
0
        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);
        }
Example #2
0
        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);
            }
        }