/// <summary>
        /// Assigns the <see cref="GLTran.RefNbr"/>.
        /// The method either generates a reference number based on the specified numbering sequence (<see cref="extRefNbrNumbering"/>),
        /// or takes it from the BatchNbr-RefNbr dictionary (<see cref="_batchKeys"/>).
        /// If the number is generated it is also stored in the dictionary.
        /// </summary>
        /// <param name="sender">cache of type <see cref="GLTran"/>. Will be used to get a cache of type <see cref="Batch"/>.</param>
        /// <param name="tran">transaction, to which the RefNbr is assigned</param>
        /// <param name="generateIfNew">specifies whether a RefNbr must be generated based on the sequence if the RefNbr is not found for the current Batch</param>
        private void AssignRefNbr(PXCache sender, GLTran tran, bool generateIfNew)
        {
            PXCache batchCache = sender.Graph.Caches[typeof(Batch)];
            Batch   batch      = (Batch)batchCache.Current;

            if (batch != null && string.IsNullOrEmpty(batch.BatchNbr) == false)
            {
                string batchNbr = batch.BatchNbr;
                if (string.IsNullOrEmpty(tran.RefNbr))
                {
                    string extRefNbr = null;
                    if (!_batchKeys.TryGetValue(batchNbr, out extRefNbr) && generateIfNew)
                    {
                        extRefNbr = AutoNumberAttribute.GetNextNumber(sender, tran, extRefNbrNumbering, tran.TranDate);
                        _batchKeys.Add(batchNbr, extRefNbr);
                    }

                    if (extRefNbr != null)
                    {
                        tran.RefNbr = extRefNbr;
                    }

                    PXDBLiteDefaultAttribute.SetDefaultForInsert <GLTran.refNbr>(sender, tran, false);
                }
            }
        }
示例#2
0
        public void OnRowPersisting(PXCache sender, PXRowPersistingEventArgs e)
        {
            GLTran tran = (GLTran)e.Row;

            if (tran != null && ((e.Operation & PXDBOperation.Command) != PXDBOperation.Delete))
            {
                PXCache batchCache = sender.Graph.Caches[typeof(Batch)];
                Batch   batch      = (Batch)batchCache.Current;
                if (batch != null && string.IsNullOrEmpty(batch.BatchNbr) == false)
                {
                    string batchNbr = batch.BatchNbr;
                    if (string.IsNullOrEmpty(tran.RefNbr))
                    {
                        string extRefNbr;
                        if (!_batchKeys.TryGetValue(batchNbr, out extRefNbr))
                        {
                            extRefNbr = AutoNumberAttribute.GetNextNumber(sender, tran, extRefNbrNumbering, tran.TranDate);
                            _batchKeys.Add(batchNbr, extRefNbr);
                        }
                        tran.RefNbr = extRefNbr;

                        PXDBLiteDefaultAttribute.SetDefaultForInsert <GLTran.refNbr>(sender, tran, false);
                    }
                }
            }
        }
示例#3
0
        protected override bool SetRefNbr(PXCache cache, object row)
        {
            bool?userNumbering = this.UserNumbering;
            bool flag          = true;

            if (userNumbering.GetValueOrDefault() == flag & userNumbering.HasValue)
            {
                return(true);
            }
            FLXProject flxProject  = row as FLXProject;
            char       ch          = '-';
            string     origProjNbr = flxProject.OrigProjNbr;

            if (string.IsNullOrEmpty(origProjNbr))
            {
                FLXSetup flxSetup = SelectFrom <FLXSetup> .View.Select(cache.Graph);

                flxProject.ProjectNbr = AutoNumberAttribute.GetNextNumber(cache, row, flxSetup.ProjNbrNumberingID, cache.Graph.Accessinfo.BusinessDate) + ch.ToString() + "0";
            }
            else
            {
                string projectNbr = origProjNbr.Substring(0, origProjNbr.IndexOf(ch));
                string str        = string.Format("{0}{1}{2}", (object)projectNbr, (object)ch, (object)FLXProjAutoNumberAttribute.CountRecords(cache.Graph, projectNbr));
                flxProject.ProjectNbr = str;
            }
            return(true);
        }
示例#4
0
 public UsageMaint()
 {
     if (!PXAccess.FeatureInstalled <FeaturesSet.projectModule>())
     {
         AutoNumberAttribute.SetNumberingId <PMRegister.refNbr>(Document.Cache, arsetup.Current.UsageNumberingID);
     }
     Document.Cache.Insert();
 }
示例#5
0
        protected void Vendor_RowPersisting(PXCache cache, PXRowPersistingEventArgs e)
        {
            var row = (Vendor)e.Row;

            string vClass = row.VendorClassID;

            if (vClass == "FORWARDER")
            {
                AutoNumberAttribute.SetNumberingId <Vendor.acctCD>(cache, "FORWARDER");
            }
        }
示例#6
0
        public UsageMaint()
        {
            PXImportAttribute importAttribute = UnBilled.GetAttribute <PXImportAttribute>();

            importAttribute.MappingPropertiesInit += ImportAttributeMappingPropertiesHandler;

            if (!PXAccess.FeatureInstalled <FeaturesSet.projectModule>())
            {
                AutoNumberAttribute.SetNumberingId <PMRegister.refNbr>(Document.Cache, arsetup.Current.UsageNumberingID);
            }

            EnsurePMDocumentCreated();
        }
        static PropertyData GetUserDefinedPropertyData(PropertyInfo info, PropertyInfo dbProp)
        {
            var isBlob     = info.PropertyType.IsA <Blob>();
            var targetProp = dbProp ?? info;
            var columnName = info.Name + "_FileName".OnlyWhen(isBlob);

            return(new PropertyData(isBlob)
            {
                IsAutoNumber = AutoNumberAttribute.IsAutoNumber(info),
                IsCustomPrimaryKey = PrimaryKeyAttribute.IsPrimaryKey(info),
                Name = columnName,
                ParameterName = columnName,
                PropertyInfo = targetProp,
                NonGenericType = IsNullableType(targetProp) ? Nullable.GetUnderlyingType(targetProp.PropertyType) : targetProp.PropertyType
            });
        }
        private void SetNumbering(PXCache sender, Batch row)
        {
            if (row == null)
            {
                return;
            }
            if (Base.IsWithinContext)
            {
                Numbering numbering = PXSelectJoin <Numbering,
                                                    InnerJoin <GLWorkBook, On <GLWorkBook.voucherNumberingID, Equal <Numbering.numberingID> > >,
                                                    Where <GLWorkBook.workBookID, Equal <Required <GLWorkBook.workBookID> > > > .Select(this.Base, Base.GetContextValue <GLVoucherBatch.workBookID>());

                AutoNumberAttribute.SetNumberingId <Batch.batchNbr>(sender, row.Module, numbering.NumberingID);
                if (numbering.UserNumbering == true)
                {
                    sender.RaiseExceptionHandling <Batch.batchNbr>(row, row.BatchNbr, new PXException(GL.Messages.ManualNumberingDisabled));
                }
            }
        }
示例#9
0
        public virtual void AssignNumbers(ARPaymentEntryExt pe, ARPayment doc, ref string NextCheckNbr)
        {
            pe.RowPersisting.RemoveHandler <ARAdjust>(pe.ARAdjust_RowPersisting);
            pe.Clear(PXClearOption.PreserveTimeStamp);
            doc = pe.Document.Current = pe.Document.Search <ARPayment.refNbr>(doc.RefNbr, doc.DocType);
            PaymentMethodAccount det = pe.cashaccountdetail.Select();

            var payExt = PXCache <ARPayment> .GetExtension <ARPaymentExt>(pe.Document.Current);

            if (!string.IsNullOrEmpty(NextCheckNbr))
            {
                if (String.IsNullOrEmpty(pe.Document.Current.ExtRefNbr))
                {
                    payExt.StubCntr = 1;
                    payExt.BillCntr = 0;
                    pe.Document.Current.ExtRefNbr = NextCheckNbr;
                    if (String.IsNullOrEmpty(NextCheckNbr))
                    {
                        throw new PXException(AP.Messages.NextCheckNumberIsRequiredForProcessing);
                    }

                    pe.cashaccountdetail.Update(det); // det.APLastRefNumber was modified in StoreStubNumber method

                    NextCheckNbr                         = AutoNumberAttribute.NextNumber(NextCheckNbr);
                    payExt.Printed                       = true;
                    pe.Document.Current.Hold             = false;
                    pe.Document.Current.UpdateNextNumber = true;
                    pe.Document.Update(pe.Document.Current);
                }
                else
                {
                    if (payExt.Printed != true || pe.Document.Current.Hold != false)
                    {
                        payExt.Printed           = true;
                        pe.Document.Current.Hold = false;
                        pe.Document.Update(pe.Document.Current);
                    }
                }
            }
        }
        protected virtual void ARCashSale_RowPersisting(PXCache sender, PXRowPersistingEventArgs e, PXRowPersisting bs)
        {
            if (bs != null)
            {
                bs(sender, e);
            }
            AR.Standalone.ARCashSale row = e.Row as AR.Standalone.ARCashSale;
            if (row == null)
            {
                return;
            }
            if (Base.IsWithinContext)
            {
                Numbering numbering = PXSelectJoin <Numbering,
                                                    InnerJoin <GLWorkBook, On <GLWorkBook.voucherNumberingID, Equal <Numbering.numberingID> > >,
                                                    Where <GLWorkBook.workBookID, Equal <Required <GLWorkBook.workBookID> > > > .Select(this.Base, Base.GetContextValue <GLVoucherBatch.workBookID>());

                AutoNumberAttribute.SetNumberingId <AR.Standalone.ARCashSale.refNbr>(sender, row.DocType, numbering.NumberingID);
                if (numbering.UserNumbering == true)
                {
                    sender.RaiseExceptionHandling <AR.Standalone.ARCashSale.refNbr>(row, row.RefNbr, new PXException(GL.Messages.ManualNumberingDisabled));
                }
            }
        }
 /* Override SetNumberingId<> by event */
 public void _(Events.RowPersisting <AVLTable> eAVLTable)
 {
     AutoNumberAttribute.SetNumberingId <AVLTable.avlnbr>(eAVLTable.Cache, "AVL"); //AVL is the numbering sequence setting in system
 }
		protected virtual void AppendMatrixItemIDSegment(
			StringBuilder res, InventoryItem template,
			INMatrixGenerationRule genRule, bool isLastSegment, MatrixInventoryItem newItem, bool useLastAutoNumberValue)
		{
			string segValue = string.Empty;
			switch (genRule.SegmentType)
			{
				case INMatrixGenerationRule.segmentType.TemplateID:
					segValue = template.InventoryCD;
					break;
				case INMatrixGenerationRule.segmentType.TemplateDescription:
					segValue = template.Descr;
					break;
				case INMatrixGenerationRule.segmentType.AttributeCaption:
					for (int i = 0; i < newItem.AttributeIDs.Length; i++)
					{
						if (newItem.AttributeIDs[i].Equals(genRule.AttributeID, StringComparison.OrdinalIgnoreCase))
						{
							segValue = newItem.AttributeValueDescrs[i];
							break;
						}
					}
					break;
				case INMatrixGenerationRule.segmentType.AttributeValue:
					for (int i = 0; i < newItem.AttributeIDs.Length; i++)
					{
						if (newItem.AttributeIDs[i].Equals(genRule.AttributeID, StringComparison.OrdinalIgnoreCase))
						{
							segValue = newItem.AttributeValues[i];
							break;
						}
					}
					break;
				case INMatrixGenerationRule.segmentType.Constant:
					segValue = genRule.Constant;
					break;
				case INMatrixGenerationRule.segmentType.Space:
					segValue = " ";
					break;
				case INMatrixGenerationRule.segmentType.AutoNumber when !useLastAutoNumberValue:
					segValue = AutoNumberAttribute.GetNextNumber(_graph.Caches[typeof(InventoryItem)], null, genRule.NumberingID, _graph.Accessinfo.BusinessDate);
					break;
				case INMatrixGenerationRule.segmentType.AutoNumber when useLastAutoNumberValue:
					var numberingSequence = AutoNumberAttribute.GetNumberingSequence(genRule.NumberingID, _graph.Accessinfo.BranchID, _graph.Accessinfo.BusinessDate);
					segValue = numberingSequence?.LastNbr;
					if (string.IsNullOrEmpty(segValue))
						segValue = AutoNumberAttribute.GetNextNumber(_graph.Caches[typeof(InventoryItem)], null, genRule.NumberingID, _graph.Accessinfo.BusinessDate);
					break;

				default:
					throw new PXArgumentException(nameof(INMatrixGenerationRule));
			}

			segValue = segValue ?? string.Empty;

			if (segValue.Length > genRule.NumberOfCharacters)
			{
				segValue = segValue.Substring(0, (int)genRule.NumberOfCharacters);
			}
			else if (segValue.Length < genRule.NumberOfCharacters)
			{
				segValue = segValue.PadRight((int)genRule.NumberOfCharacters);
			}

			res.Append(segValue);

			if (!isLastSegment)
			{
				if (genRule.UseSpaceAsSeparator == true)
				{
					res.Append(' ');
				}
				else
				{
					res.Append(genRule.Separator);
				}
			}
		}
示例#13
0
        public virtual void GenerateProc(Schedule s, short Times, DateTime runDate)
        {
            string             LastBatchNbr = "0000000000";
            Int64              LastInfoID   = -1;
            List <ScheduleDet> sd           = MakeSchedule(s, Times, runDate);

            using (PXTransactionScope ts = new PXTransactionScope())
            {
                foreach (ScheduleDet d in sd)
                {
                    foreach (BatchNew b in PXSelect <BatchNew, Where <BatchNew.scheduleID, Equal <Optional <Schedule.scheduleID> >, And <BatchNew.scheduled, Equal <boolTrue> > > > .Select(this, s.ScheduleID))
                    {
                        BatchNew copy = PXCache <BatchNew> .CreateCopy(b);

                        copy.OrigBatchNbr = copy.BatchNbr;
                        copy.OrigModule   = copy.Module;
                        copy.CuryInfoID   = null;
                        copy.NumberCode   = "GLREC";
                        copy.NoteID       = null;

                        CurrencyInfo info = (CurrencyInfo)PXSelect <CurrencyInfo, Where <CurrencyInfo.curyInfoID, Equal <Required <CurrencyInfo.curyInfoID> > > > .Select(this, b.CuryInfoID);

                        if (info != null)
                        {
                            CurrencyInfo infocopy = PXCache <CurrencyInfo> .CreateCopy(info);

                            infocopy.CuryInfoID = LastInfoID;
                            copy.CuryInfoID     = LastInfoID;
                            CuryInfo_Created.Cache.Insert(infocopy);
                        }

                        copy.Posted    = false;
                        copy.Released  = false;
                        copy.Status    = "B";
                        copy.Scheduled = false;

                        copy.DateEntered  = d.ScheduledDate;
                        copy.FinPeriodID  = d.ScheduledPeriod;
                        copy.TranPeriodID = null;

                        copy.BatchNbr    = LastBatchNbr;
                        copy.RefBatchNbr = LastBatchNbr;
                        LastBatchNbr     = AutoNumberAttribute.NextNumber(LastBatchNbr);
                        LastInfoID--;

                        copy = (BatchNew)Batch_Created.Cache.Insert(copy);

                        CurrencyInfoAttribute.SetEffectiveDate <Batch.dateEntered>(Batch_Created.Cache, new PXFieldUpdatedEventArgs(copy, null, false));
                        PXNoteAttribute.SetNote(Batch_Created.Cache, copy, PXNoteAttribute.GetNote(Caches[typeof(BatchNew)], b));
                        PXNoteAttribute.SetFileNotes(Batch_Created.Cache, copy, PXNoteAttribute.GetFileNotes(Caches[typeof(BatchNew)], b));

                        foreach (GLTranNew tran in PXSelect <GLTranNew, Where <GLTranNew.module, Equal <Required <GLTranNew.module> >, And <GLTranNew.batchNbr, Equal <Required <GLTranNew.batchNbr> > > > > .Select(this, b.Module, b.BatchNbr))
                        {
                            GLTranNew trancopy = PXCache <GLTranNew> .CreateCopy(tran);

                            trancopy.OrigBatchNbr = trancopy.BatchNbr;
                            trancopy.OrigModule   = trancopy.Module;
                            trancopy.BatchNbr     = copy.BatchNbr;
                            trancopy.RefBatchNbr  = copy.RefBatchNbr;
                            trancopy.CuryInfoID   = copy.CuryInfoID;
                            trancopy.CATranID     = null;

                            trancopy.TranDate     = d.ScheduledDate;
                            trancopy.FinPeriodID  = d.ScheduledPeriod;
                            trancopy.TranPeriodID = d.ScheduledPeriod;
                            Tran_Created.Cache.Insert(trancopy);
                        }
                    }

                    s.LastRunDate = d.ScheduledDate;
                    Running_Schedule.Cache.Update(s);
                }
                Running_Schedule.Cache.Persist(PXDBOperation.Update);

                Batch_Created.Cache.Persist(PXDBOperation.Insert);
                Batch_Created.Cache.Persist(PXDBOperation.Update);

                foreach (GLTranNew tran in Tran_Created.Cache.Inserted)
                {
                    foreach (BatchNew batch in Batch_Created.Cache.Cached)
                    {
                        if (object.Equals(batch.RefBatchNbr, tran.RefBatchNbr))
                        {
                            tran.BatchNbr   = batch.BatchNbr;
                            tran.CuryInfoID = batch.CuryInfoID;
                            if (!string.IsNullOrEmpty(batch.RefNbr))
                            {
                                tran.RefNbr = batch.RefNbr;
                            }
                            break;
                        }
                    }
                }
                Tran_Created.Cache.Normalize();

                Tran_Created.Cache.Persist(PXDBOperation.Insert);
                Tran_Created.Cache.Persist(PXDBOperation.Update);
                Caches[typeof(CA.CADailySummary)].Persist(PXDBOperation.Insert);

                ts.Complete(this);
            }
            Running_Schedule.Cache.Persisted(false);
            Batch_Created.Cache.Persisted(false);
            Tran_Created.Cache.Persisted(false);
            Caches[typeof(CA.CADailySummary)].Persisted(false);
        }
示例#14
0
        protected virtual void PrintChecksFilter_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
        {
            bool SuggestNextNumber   = false;
            PrintChecksFilter filter = (PrintChecksFilter)e.Row;

            PXUIFieldAttribute.SetVisible <PrintChecksFilter.curyID>(sender, null, PXAccess.FeatureInstalled <FeaturesSet.multicurrency>());

            if (e.Row != null &&
                cashaccountdetail.Current != null &&
                (!Equals(cashaccountdetail.Current.CashAccountID, filter.PayAccountID) ||
                 !Equals(cashaccountdetail.Current.PaymentMethodID, filter.PayTypeID)))
            {
                cashaccountdetail.Current = null;
                SuggestNextNumber         = true;
            }

            if (e.Row != null && paymenttype.Current != null && (!Equals(paymenttype.Current.PaymentMethodID, filter.PayTypeID)))
            {
                paymenttype.Current = null;
            }

            if (e.Row != null && string.IsNullOrEmpty(filter.NextCheckNbr))
            {
                SuggestNextNumber = true;
            }

            PXUIFieldAttribute.SetVisible <PrintChecksFilter.nextCheckNbr>(sender, null, true);

            if (e.Row == null)
            {
                return;
            }

            if (cashaccountdetail.Current != null && true == cashaccountdetail.Current.APAutoNextNbr && SuggestNextNumber)
            {
                filter.NextCheckNbr = PaymentRefAttribute.GetNextPaymentRef(
                    sender.Graph,
                    cashaccountdetail.Current.CashAccountID,
                    cashaccountdetail.Current.PaymentMethodID);
            }

            bool printOrExport = paymenttype.Current == null || paymenttype.Current.PrintOrExport == true;

            bool isNextNumberDuplicated = false;

            if (paymenttype.Current != null && paymenttype.Current.PrintOrExport == true && string.IsNullOrEmpty(filter.NextCheckNbr))
            {
                sender.RaiseExceptionHandling <PrintChecksFilter.nextCheckNbr>(e.Row, filter.NextCheckNbr,
                                                                               new PXSetPropertyException(Messages.NextCheckNumberIsRequiredForProcessing, PXErrorLevel.Warning));
            }
            else if (!string.IsNullOrEmpty(filter.NextCheckNbr) && !AutoNumberAttribute.CanNextNumber(filter.NextCheckNbr))
            {
                sender.RaiseExceptionHandling <PrintChecksFilter.nextCheckNbr>(e.Row, filter.NextCheckNbr,
                                                                               new PXSetPropertyException(Messages.NextCheckNumberCanNotBeInc, PXErrorLevel.Warning));
            }
            else if (paymenttype.Current != null && paymenttype.Current.APPrintChecks == true &&
                     (isNextNumberDuplicated = filter.IsNextNumberDuplicated(sender.Graph, filter.NextCheckNbr)))
            {
                sender.RaiseExceptionHandling <PrintChecksFilter.nextCheckNbr>(e.Row, filter.NextCheckNbr,
                                                                               new PXSetPropertyException(Messages.ConflictWithExistingCheckNumber, filter.NextCheckNbr));
            }
            else
            {
                sender.RaiseExceptionHandling <PrintChecksFilter.nextCheckNbr>(e.Row, filter.NextCheckNbr, null);
            }

            APPaymentList.SetProcessEnabled(!isNextNumberDuplicated && printOrExport && filter.PayTypeID != null);
            APPaymentList.SetProcessAllEnabled(!isNextNumberDuplicated && printOrExport && filter.PayTypeID != null);

            if (HttpContext.Current != null && Filter.Current.BranchID != PXAccess.GetBranchID())
            {
                Filter.Current.BranchID = PXAccess.GetBranchID();
            }

            PaymentMethod pt = paymenttype.Current;

            APPaymentList.SetProcessDelegate(
                delegate(List <APPayment> list)
            {
                APPrintChecks graph = CreateInstance <APPrintChecks>();
                graph.PrintPayments(list, filter, pt);
            }
                );
        }
示例#15
0
        protected virtual void PrintPayments(List <APPayment> list, PrintChecksFilter filter, PaymentMethod paymentMethod)
        {
            if (list.Count == 0)
            {
                return;
            }

            if (paymentMethod.UseForAP == true)
            {
                if (paymentMethod.APPrintChecks == true && string.IsNullOrEmpty(paymentMethod.APCheckReportID))
                {
                    throw new PXException(Messages.FieldNotSetInPaymentMethod, PXUIFieldAttribute.GetDisplayName <PaymentMethod.aPCheckReportID>(paymenttype.Cache), paymentMethod.PaymentMethodID);
                }

                if (paymentMethod.APPrintChecks == true && paymentMethod.APPrintRemittance == true && string.IsNullOrEmpty(paymentMethod.APRemittanceReportID))
                {
                    throw new PXException(Messages.FieldNotSetInPaymentMethod, PXUIFieldAttribute.GetDisplayName <PaymentMethod.aPRemittanceReportID>(paymenttype.Cache), paymentMethod.PaymentMethodID);
                }
            }

            bool printAdditionRemit = false;

            if (paymentMethod.APCreateBatchPayment == true)
            {
                CABatch batch = CreateBatchPayment(list, filter);
                if (batch != null)
                {
                    bool           failed = false;
                    APPaymentEntry pe     = CreateInstance <APPaymentEntry>();

                    string NextCheckNbr = filter.NextCheckNbr;
                    foreach (APPayment pmt in list)
                    {
                        APPayment payment = pmt;
                        PXProcessing <APPayment> .SetCurrentItem(payment);

                        try
                        {
                            payment = pe.Document.Search <APPayment.refNbr>(payment.RefNbr, payment.DocType);
                            if (payment.PrintCheck != true)
                            {
                                throw new PXException(Messages.CantPrintNonprintableCheck);
                            }
                            if ((payment.DocType == APDocType.Check || payment.DocType == APDocType.QuickCheck) &&
                                payment.Status != APDocStatus.PendingPrint)
                            {
                                throw new PXException(Messages.ChecksMayBePrintedInPendingPrintStatus);
                            }

                            AssignNumbers(pe, payment, ref NextCheckNbr, true);

                            if (payment.Passed == true)
                            {
                                pe.TimeStamp = payment.tstamp;
                            }
                            pe.Save.Press();
                            payment.tstamp = pe.TimeStamp;
                            pe.Clear();
                        }
                        catch (PXException e)
                        {
                            PXProcessing <APPayment> .SetError(e);

                            failed = true;
                        }
                    }
                    if (failed)
                    {
                        throw new PXOperationCompletedWithErrorException(Messages.APPaymentsAreAddedToTheBatchButWasNotUpdatedCorrectly, batch.BatchNbr);
                    }
                    RedirectToResultWithCreateBatch(batch);
                }
            }
            else
            {
                APReleaseChecks     pp          = CreateInstance <APReleaseChecks>();
                ReleaseChecksFilter filter_copy = PXCache <ReleaseChecksFilter> .CreateCopy(pp.Filter.Current);

                filter_copy.PayAccountID = filter.PayAccountID;
                filter_copy.PayTypeID    = filter.PayTypeID;
                filter_copy.CuryID       = filter.CuryID;
                pp.Filter.Cache.Update(filter_copy);

                APPaymentEntry pe             = CreateInstance <APPaymentEntry>();
                bool           failed         = false;
                Dictionary <string, string> d = new Dictionary <string, string>();

                string nextCheckNbr = filter.NextCheckNbr;
                string prevCheckNbr = nextCheckNbr;

                int idxReportFilter = 0;
                foreach (APPayment pmt in list)
                {
                    APPayment payment = pmt;
                    PXProcessing <APPayment> .SetCurrentItem(payment);

                    try
                    {
                        prevCheckNbr = nextCheckNbr;
                        if (filter.IsNextNumberDuplicated(this, nextCheckNbr))
                        {
                            string duplicate = nextCheckNbr;
                            nextCheckNbr = AutoNumberAttribute.NextNumber(nextCheckNbr);
                            throw new PXException(Messages.ConflictWithExistingCheckNumber, duplicate);
                        }

                        payment = pe.Document.Search <APPayment.refNbr>(payment.RefNbr, payment.DocType);
                        if (payment.PrintCheck != true)
                        {
                            throw new PXException(Messages.CantPrintNonprintableCheck);
                        }
                        if ((payment.DocType == APDocType.Check || payment.DocType == APDocType.QuickCheck) &&
                            payment.Status != APDocStatus.PendingPrint)
                        {
                            throw new PXException(Messages.ChecksMayBePrintedInPendingPrintStatus);
                        }
                        AssignNumbers(pe, payment, ref nextCheckNbr);

                        if (payment.Passed == true)
                        {
                            pe.TimeStamp = payment.tstamp;
                        }
                        pe.Save.Press();
                        payment.tstamp = pe.TimeStamp;
                        pe.Clear();

                        APPayment seldoc = pe.Document.Search <APPayment.refNbr>(payment.RefNbr, payment.DocType);
                        seldoc.Selected = true;
                        seldoc.Passed   = true;
                        seldoc.tstamp   = payment.tstamp;
                        pp.APPaymentList.Cache.Update(seldoc);
                        pp.APPaymentList.Cache.SetStatus(seldoc, PXEntryStatus.Updated);

                        printAdditionRemit |= seldoc.BillCntr > paymentMethod.APStubLines;

                        StringBuilder sbDocType = new StringBuilder("APPayment.DocType");
                        sbDocType.Append(Convert.ToString(idxReportFilter));
                        StringBuilder sbRefNbr = new StringBuilder("APPayment.RefNbr");
                        sbRefNbr.Append(Convert.ToString(idxReportFilter));

                        idxReportFilter++;

                        d[sbDocType.ToString()] = payment.DocType == APDocType.QuickCheck ? APDocType.QuickCheck : APDocType.Check;
                        d[sbRefNbr.ToString()]  = payment.RefNbr;
                        PXProcessing <APPayment> .SetProcessed();
                    }
                    catch (PXException e)
                    {
                        PXProcessing <APPayment> .SetError(e);

                        failed       = true;
                        nextCheckNbr = prevCheckNbr;
                    }
                }

                if (failed)
                {
                    PXReportRequiredException report = null;
                    if (d.Count > 0)
                    {
                        d[ReportMessages.CheckReportFlag] = ReportMessages.CheckReportFlagValue;
                        report = new PXReportRequiredException(d, paymentMethod.APCheckReportID, PXBaseRedirectException.WindowMode.New, "Check");
                    }
                    throw new PXOperationCompletedWithErrorException(GL.Messages.DocumentsNotReleased, report);
                }
                else
                {
                    if (d.Count > 0)
                    {
                        RedirectToResultNoBatch(pp, d, paymentMethod, printAdditionRemit, nextCheckNbr);
                    }
                }
            }
        }
示例#16
0
        public virtual void AssignNumbers(APPaymentEntry pe, APPayment doc, ref string NextCheckNbr, bool skipStubs = false)
        {
            pe.RowPersisting.RemoveHandler <APAdjust>(pe.APAdjust_RowPersisting);
            pe.Clear();
            doc = pe.Document.Current = pe.Document.Search <APPayment.refNbr>(doc.RefNbr, doc.DocType);
            PaymentMethodAccount det = pe.cashaccountdetail.Select();

            doc.IsPrintingProcess = true;             // indicates that the payment under printing process (to prevent update by PaymentRefAttribute)

            if (string.IsNullOrEmpty(NextCheckNbr))
            {
                throw new PXException(Messages.NextCheckNumberIsRequiredForProcessing);
            }

            if (string.IsNullOrEmpty(pe.Document.Current.ExtRefNbr))
            {
                pe.Document.Current.StubCntr  = 1;
                pe.Document.Current.BillCntr  = 0;
                pe.Document.Current.ExtRefNbr = NextCheckNbr;

                if (pe.Document.Current.DocType == APDocType.QuickCheck && pe.Document.Current.CuryOrigDocAmt <= 0m)
                {
                    throw new PXException(Messages.ZeroCheck_CannotPrint);
                }

                if (!skipStubs)                         // print check
                {
                    APAdjust[]    adjustments = pe.Adjustments_print.Select().RowCast <APAdjust>().ToArray();
                    PaymentMethod pt          = pe.paymenttype.Select();
                    int           stubCount   = (int)Math.Ceiling(adjustments.Length / (decimal)(pt.APStubLines ?? 1));
                    if (stubCount > 1 && pt.APPrintRemittance != true)
                    {
                        string   endNumber  = AutoNumberAttribute.NextNumber(NextCheckNbr, stubCount - 1);
                        string[] duplicates = PXSelect <CashAccountCheck,
                                                        Where <CashAccountCheck.accountID, Equal <Required <PrintChecksFilter.payAccountID> >,
                                                               And <CashAccountCheck.paymentMethodID, Equal <Required <PrintChecksFilter.payTypeID> >,
                                                                    And <CashAccountCheck.checkNbr, GreaterEqual <Required <PrintChecksFilter.nextCheckNbr> >,
                                                                         And <CashAccountCheck.checkNbr, LessEqual <Required <PrintChecksFilter.nextCheckNbr> > > > > > >
                                              .Select(this, det.CashAccountID, det.PaymentMethodID, NextCheckNbr, endNumber)
                                              .RowCast <CashAccountCheck>()
                                              .Select(check => check.CheckNbr)
                                              .ToArray();

                        if (duplicates.Any())
                        {
                            throw new PXException(
                                      Messages.TooSmallCheckNumbersGap,
                                      stubCount,
                                      NextCheckNbr,
                                      endNumber,
                                      string.Join(",", duplicates));
                        }
                    }

                    short ordinalInStub = 0;
                    int   stubOrdinal   = 0;
                    foreach (APAdjust adj in adjustments)
                    {
                        pe.Document.Current.BillCntr++;

                        if (ordinalInStub > pt.APStubLines - 1)
                        {
                            //AssignCheckNumber only for first StubLines in check, other/all lines will be printed on remittance report
                            if (pt.APPrintRemittance == true)
                            {
                                adj.StubNbr = null;
                                pe.Adjustments.Cache.Update(adj);
                                continue;
                            }
                            NextCheckNbr = AutoNumberAttribute.NextNumber(NextCheckNbr);

                            pe.Document.Current.StubCntr++;
                            ordinalInStub = 0;
                            stubOrdinal++;
                        }

                        SetAdjustmentStubNumber(pe, doc, adj, NextCheckNbr);
                        StoreStubNumber(pe, doc, det, NextCheckNbr, stubOrdinal);

                        ordinalInStub++;
                    }
                }
                else                         // create batch payment
                {
                    //Update last number
                    det.APLastRefNbr = NextCheckNbr;
                }

                pe.cashaccountdetail.Update(det);                         // det.APLastRefNumber was modified in StoreStubNumber method

                NextCheckNbr = AutoNumberAttribute.NextNumber(NextCheckNbr);
                pe.Document.Current.Printed = true;
                pe.Document.Current.Hold    = false;
                pe.Document.Update(pe.Document.Current);
            }
            else
            {
                if (pe.Document.Current.Printed != true || pe.Document.Current.Hold == true)
                {
                    pe.Document.Current.Printed = true;
                    pe.Document.Current.Hold    = false;
                    pe.Document.Update(pe.Document.Current);
                }
            }
        }
示例#17
0
        protected virtual void PrintChecksFilter_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
        {
            bool SuggestNextNumber = false;
            PrintChecksFilter row  = (PrintChecksFilter)e.Row;

            PXUIFieldAttribute.SetVisible <PrintChecksFilter.curyID>(sender, null, (bool)CMSetup.Current.MCActivated);

            if (e.Row != null && cashaccountdetail.Current != null && (object.Equals(cashaccountdetail.Current.CashAccountID, row.PayAccountID) == false || object.Equals(cashaccountdetail.Current.PaymentMethodID, row.PayTypeID) == false))
            {
                cashaccountdetail.Current = null;
                SuggestNextNumber         = true;
            }

            if (e.Row != null && paymenttype.Current != null && (object.Equals(paymenttype.Current.PaymentMethodID, row.PayTypeID) == false))
            {
                paymenttype.Current = null;
            }

            if (e.Row != null && string.IsNullOrEmpty(row.NextCheckNbr))
            {
                SuggestNextNumber = true;
            }

            PXUIFieldAttribute.SetVisible <PrintChecksFilter.nextCheckNbr>(sender, null, true);

            if (e.Row == null)
            {
                return;
            }

            if (cashaccountdetail.Current != null && (bool)cashaccountdetail.Current.APAutoNextNbr == true)
            {
                //PXUIFieldAttribute.SetVisible<PrintChecksFilter.nextCheckNbr>(sender, null, true);
                if (SuggestNextNumber)
                {
                    if (string.IsNullOrEmpty(cashaccountdetail.Current.APLastRefNbr) == false)
                    {
                        row.NextCheckNbr = AutoNumberAttribute.NextNumber(cashaccountdetail.Current.APLastRefNbr);
                    }
                    else
                    {
                        row.NextCheckNbr = string.Empty;
                    }
                }
            }
            else
            {
                //PXUIFieldAttribute.SetVisible<PrintChecksFilter.nextCheckNbr>(sender, null, false);
                //row.NextCheckNbr = null;
            }

            if (paymenttype.Current != null && ((bool)paymenttype.Current.APPrintChecks == false && (bool)paymenttype.Current.APCreateBatchPayment == false))
            {
                sender.RaiseExceptionHandling <PrintChecksFilter.payTypeID>(e.Row, row.PayTypeID, new PXSetPropertyException(Messages.PaymentTypeNoPrintCheck, PXErrorLevel.Warning));
            }
            else
            {
                sender.RaiseExceptionHandling <PrintChecksFilter.payTypeID>(e.Row, row.PayTypeID, null);
            }

            if (paymenttype.Current != null && paymenttype.Current.PrintOrExport == true && String.IsNullOrEmpty(row.NextCheckNbr))
            {
                sender.RaiseExceptionHandling <PrintChecksFilter.nextCheckNbr>(e.Row, row.NextCheckNbr, new PXSetPropertyException(Messages.NextCheckNumberIsRequiredForProcessing, PXErrorLevel.Warning));
            }
            else
            {
                if (!String.IsNullOrEmpty(row.NextCheckNbr) && !AutoNumberAttribute.CanNextNumber(row.NextCheckNbr))
                {
                    sender.RaiseExceptionHandling <PrintChecksFilter.nextCheckNbr>(e.Row, row.NextCheckNbr, new PXSetPropertyException(Messages.NextCheckNumberCanNotBeInc, PXErrorLevel.Warning));
                }
                else
                {
                    sender.RaiseExceptionHandling <PrintChecksFilter.nextCheckNbr>(e.Row, row.NextCheckNbr, null);
                }
            }


            PrintChecksFilter filter = Filter.Current;
            PaymentMethod     pt     = paymenttype.Current;

            APPaymentList.SetProcessTooltip(Messages.ProcessSelectedRecordsTooltip);
            APPaymentList.SetProcessAllTooltip(Messages.ProcessAllRecordsTooltip);
            APPaymentList.SetProcessDelegate(
                delegate(List <APPayment> list)
            {
                var graph = PXGraph.CreateInstance <APPrintChecks>();
                graph.PrintPayments(list, filter, pt);
                //CreateBatchPayment(list, filter);
            }
                );
        }
示例#18
0
        protected virtual void _(Events.RowSelected <FLXProject> e)
        {
            string newNumberSymbol = AutoNumberAttribute.GetNewNumberSymbol <FLXProject.projectNbr>(e.Cache, (object)e.Row);

            this.CreateSubProj.SetEnabled(e.Row.ProjectNbr != newNumberSymbol && string.IsNullOrEmpty(e.Row.OrigProjNbr));
        }
示例#19
0
        public void Export(List <TWNGUITrans> tWNGUITrans)
        {
            try
            {
                TWNGUIPreferences gUIPreferences = gUIPreferSetup.Current;

                int    count = 1;
                string lines = "", fileName = "";

                using (MemoryStream stream = new MemoryStream())
                {
                    using (StreamWriter sw = new StreamWriter(stream, Encoding.ASCII))
                    {
                        fileName = gUIPreferences.OurTaxNbr + ".txt";

                        foreach (TWNGUITrans gUITrans in tWNGUITrans)
                        {
                            ourTaxNbr = gUITrans.OurTaxNbr;

                            // Reporting Code
                            lines = gUITrans.GUIFormatcode;
                            // Tax Registration
                            lines += gUIPreferences.TaxRegistrationID;
                            // Sequence Number
                            lines += AutoNumberAttribute.GetNextNumber(GUITransList.Cache, gUITrans, gUIPreferences.MediaFileNumbering, Accessinfo.BusinessDate);
                            // GUI LegalYM
                            lines += GetGUILegal(gUITrans.GUIDate.Value);
                            // Tax ID (Buyer)
                            lines += GetBuyerTaxID(gUITrans);
                            // Tax ID (Seller)
                            lines += GetSellerTaxID(gUITrans);
                            // GUI Number
                            lines += GetGUINbr(gUITrans);
                            // Net Amount
                            lines += GetNetAmt(gUITrans);
                            // Tax Group
                            lines += GetTaxGroup(gUITrans);
                            // Tax Amount
                            lines += GetTaxAmt(gUITrans);
                            // Deduction Code
                            lines += (gUITrans.DeductionCode != null || gUITrans.GUIFormatcode.StartsWith("2")) ? gUITrans.DeductionCode : new string(space, 1);
                            // Blank
                            lines += new string(space, 5);
                            // Special Tax Rate
                            lines += new string(space, 1);
                            // Summary Remark
                            lines += GetSummaryRemark(gUITrans);
                            // Export Method
                            lines += GetExportMethod(gUITrans);

                            // Only the last line does not need to be broken.
                            if (count < tWNGUITrans.Count)
                            {
                                sw.WriteLine(lines);
                                count++;
                            }
                            else
                            {
                                sw.Write(lines);
                            }
                        }

                        count = 1;
                        PXSelectBase <NumberingSequence> query = new PXSelect <NumberingSequence,
                                                                               Where <NumberingSequence.numberingID, Like <GUI2x>,
                                                                                      Or <NumberingSequence.numberingID, Like <GUI3x>,
                                                                                          And <NumberingSequence.startDate, GreaterEqual <Current <GUITransFilter.fromDate> >,
                                                                                               And <NumberingSequence.startDate, LessEqual <Current <GUITransFilter.toDate> > > > > > >(this);

                        foreach (NumberingSequence numSeq in query.Select())
                        {
                            int endNbr  = Int32.Parse(numSeq.EndNbr.Substring(2));
                            int lastNbr = Int32.Parse(numSeq.LastNbr.Substring(2));

                            if (numSeq.StartNbr.Equals(numSeq.LastNbr) || lastNbr <= endNbr)
                            {
                                lines = "\r\n";
                                // Reporting Code
                                lines += numSeq.NumberingID.Substring(numSeq.NumberingID.IndexOf('I') + 1, 2);
                                // Tax Registration
                                lines += gUIPreferences.TaxRegistrationID;
                                // Sequence Number
                                lines += AutoNumberAttribute.GetNextNumber(GUITransList.Cache, numSeq, gUIPreferences.MediaFileNumbering, Accessinfo.BusinessDate);
                                // GUI LegalYM
                                lines += GetGUILegal(Filter.Current.ToDate.Value);
                                // Tax ID (Buyer)
                                lines += numSeq.EndNbr.Substring(2);
                                // Tax ID (Seller)
                                lines += ourTaxNbr;
                                // GUI Number
                                lines += string.Format("{0}{1}", numSeq.LastNbr.Substring(0, 2), lastNbr + 1);
                                // Net Amount
                                lines += new string(zero, 12);
                                // Tax Group
                                lines += "D";
                                // Tax Amount
                                lines += new string(zero, 10);
                                // Deduction Code
                                lines += new string(space, 1);
                                // Blank
                                lines += new string(space, 5);
                                // Special Tax Rate
                                lines += new string(space, 1);
                                // Summary Remark
                                lines += "A";
                                // Export Method
                                lines += new string(space, 1);

                                sw.Write(lines);
                            }
                        }

                        sw.Close();

                        // Redirect browser to file created in memory on server
                        throw new PXRedirectToFileException(new PX.SM.FileInfo(Guid.NewGuid(), fileName,
                                                                               null, stream.ToArray(), string.Empty),
                                                            true);
                    }
                }
            }
            catch (PXException ex)
            {
                PXProcessing <TWNGUITrans> .SetError(ex);

                throw;
            }
        }
示例#20
0
        public virtual IEnumerable documents()
        {
            PendingInvoiceFilter filter = Filter.Current;
            Dictionary <CashAcctKey, PendingPaymentSummary> result = new Dictionary <CashAcctKey, PendingPaymentSummary>();

            if (filter == null && !filter.PayDate.HasValue)
            {
                return(result.Values);
            }
            PXSelectBase <APInvoice> sel = new PXSelectJoin <APInvoice,
                                                             InnerJoin <CurrencyInfo, On <CurrencyInfo.curyInfoID, Equal <APInvoice.curyInfoID> >,
                                                                        InnerJoin <CashAccount, On <CashAccount.cashAccountID, Equal <APInvoice.payAccountID> >,
                                                                                   LeftJoin <APAdjust, On <APInvoice.docType, Equal <APAdjust.adjdDocType>,
                                                                                                           And <APInvoice.refNbr, Equal <APAdjust.adjdRefNbr>, And <APAdjust.released, Equal <BitOff> > > >,
                                                                                             CrossJoin <APSetup> > > >,
                                                             Where <Where2 <Where <APInvoice.paySel, Equal <BitOn>, Or <APSetup.requireApprovePayments, Equal <False> > >,
                                                                            And2 <Where <APInvoice.released, Equal <True>, Or <APInvoice.prebooked, Equal <True> > >,
                                                                                  And <APInvoice.openDoc, Equal <BitOn> > > > >,
                                                             OrderBy <
                                                                 Asc <APInvoice.docType,
                                                                      Asc <APInvoice.refNbr> > >
                                                             >(this);

            /*if(filter.CuryID != null)
             * {
             *      sel.WhereAnd<Where<APInvoice.curyID, Equal<Current<PendingInvoiceFilter.curyID>>>>();
             * }*/
            if (filter.PayDate != null)
            {
                sel.WhereAnd <Where <APInvoice.payDate, LessEqual <Current <PendingInvoiceFilter.payDate> > > >();
            }

            if (filter.PayAccountID != null)
            {
                sel.WhereAnd <Where <APInvoice.payAccountID, Equal <Current <PendingInvoiceFilter.payAccountID> > > >();
            }

            if (filter.PayTypeID != null)
            {
                sel.WhereAnd <Where <APInvoice.payTypeID, Equal <Current <PendingInvoiceFilter.payTypeID> > > >();
            }

            APInvoiceKey lastInvoice = null;

            foreach (PXResult <APInvoice, CurrencyInfo, CashAccount, APAdjust> it in sel.Select())
            {
                APInvoice    inv    = (APInvoice)it;
                CashAccount  acct   = (CashAccount)it;
                APAdjust     adjust = (APAdjust)it;
                CurrencyInfo info   = it;
                CurrencyInfo_CuryInfoID.StoreCached(new PXCommandKey(new object[] { info.CuryInfoID }, null, null, null, 0, 1, null, false, null), new List <object> {
                    info
                });
                if (adjust.AdjdDocType != null)
                {
                    continue;                     //Skip invoices, having unreleased payments
                }
                APInvoiceKey invNbr = new APInvoiceKey(inv.DocType, inv.RefNbr);
                if (lastInvoice != null && lastInvoice.CompareTo(invNbr) == 0)
                {
                    continue;                     //Skip multiple entries for invoice
                }
                //inv.DocCount = it.RowCount;
                lastInvoice = invNbr;
                CashAcctKey           key = new CashAcctKey(inv.PayAccountID.Value, inv.PayTypeID);
                PendingPaymentSummary res = null;
                if (!result.ContainsKey(key))
                {
                    res = new PendingPaymentSummary();
                    res.PayAccountID = inv.PayAccountID;
                    res.PayTypeID    = inv.PayTypeID;
                    res.CuryID       = acct.CuryID;
                    result[key]      = res;
                    //Assign new CyrrencyInfo - to do conersion correctly. RateTypeID must be taken from the Cash Account
                    CurrencyInfo new_info = new CurrencyInfo();
                    new_info.CuryID         = res.CuryID;
                    new_info.CuryRateTypeID = acct.CuryRateTypeID;
                    new_info.CuryEffDate    = filter.PayDate;
                    new_info       = this.CurrencyInfo_CuryInfoID.Insert(new_info);
                    res.CuryInfoID = new_info.CuryInfoID;
                }
                else
                {
                    res = result[key];
                }

                APAdjust adj = new APAdjust();
                adj.VendorID    = inv.VendorID;
                adj.AdjdDocType = inv.DocType;
                adj.AdjdRefNbr  = inv.RefNbr;
                adj.AdjgDocType = APDocType.Check;
                adj.AdjgRefNbr  = AutoNumberAttribute.GetNewNumberSymbol <APPayment.refNbr>(Caches[typeof(APPayment)], new APPayment {
                    DocType = APDocType.Check
                });
                try
                {
                    PaymentEntry.CalcBalances <APInvoice, APAdjust>(this.CurrencyInfo_CuryInfoID, res.CuryInfoID, filter.PayDate, inv, adj);
                }
                catch (PXRateIsNotDefinedForThisDateException ex)
                {
                    Documents.Cache.RaiseExceptionHandling <PendingPaymentSummary.curyID>(res, res.CuryID, new PXSetPropertyException(ex.Message, PXErrorLevel.RowError));
                }
                Aggregate(res, new PXResult <APAdjust, APInvoice>(adj, inv), filter.PayDate);
            }
            return(result.Values);
        }
示例#21
0
        public static void ReleasePayments(List <APPayment> list, string Action)
        {
            APReleaseChecks graph     = PXGraph.CreateInstance <APReleaseChecks>();
            APPaymentEntry  pe        = PXGraph.CreateInstance <APPaymentEntry>();
            bool            failed    = false;
            bool            successed = false;

            string NextCheckNbr = null;

            List <APRegister>        docs    = new List <APRegister>(list.Count);
            List <string>            numbers = new List <string>();
            Dictionary <string, int> stubs   = new Dictionary <string, int>();

            for (int i = 0; i < list.Count; i++)
            {
                if (list[i].Passed == true)
                {
                    graph.TimeStamp = pe.TimeStamp = list[i].tstamp;
                }

                switch (Action)
                {
                case "R":
                    list[i].Printed = true;
                    break;

                case "D":
                    PaymentMethodAccount det = PXSelect <PaymentMethodAccount, Where <PaymentMethodAccount.cashAccountID, Equal <Required <PaymentMethodAccount.cashAccountID> >, And <PaymentMethodAccount.paymentMethodID, Equal <Required <PaymentMethodAccount.paymentMethodID> > > > > .Select(graph, list[i].CashAccountID, list[i].PaymentMethodID);

                    if (det == null || det.APAutoNextNbr == false)
                    {
                        numbers.Add(list[i].ExtRefNbr);
                        stubs[list[i].ExtRefNbr] = (int)list[i].StubCntr;
                        //null out Check Number and delete used check number if StubCounter == 1
                        list[i].ExtRefNbr = null;
                    }
                    list[i].Printed = false;
                    break;

                case "V":
                    //null out Check Number but do not delete it
                    list[i].StubCntr  = -1;
                    list[i].ExtRefNbr = null;
                    list[i].Printed   = false;
                    break;

                default:
                    continue;
                }

                if ((bool)list[i].Printed)
                {
                    try
                    {
                        APPrintChecks.AssignNumbers(pe, list[i], ref NextCheckNbr);
                        pe.Save.Press();

                        object[] persisted = PXTimeStampScope.GetPersisted(pe.Document.Cache, pe.Document.Current);
                        if (persisted == null || persisted.Length == 0)
                        {
                            //preserve timestamp which will be @@dbts after last record committed to db on previous Persist().
                            //otherwise another process updated APAdjust.
                            docs.Add(list[i]);
                        }
                        else
                        {
                            if (list[i].Passed == true)
                            {
                                pe.Document.Current.Passed = true;
                            }
                            docs.Add(pe.Document.Current);
                        }
                        successed = true;
                    }
                    catch (Exception e)
                    {
                        PXProcessing <APPayment> .SetError(i, e);

                        docs.Add(null);
                        failed = true;
                    }
                }
                else
                {
                    try
                    {
                        list[i].Hold = true;

                        graph.APPaymentList.Cache.PersistUpdated(list[i]);
                        graph.APPaymentList.Cache.Persisted(false);

                        graph.TimeStamp = PXDatabase.SelectTimeStamp();

                        if (string.IsNullOrEmpty(list[i].ExtRefNbr))
                        {
                            //try to get next number
                            graph.APPaymentList.Cache.SetDefaultExt <APPayment.extRefNbr>(list[i]);
                            if (string.IsNullOrEmpty(list[i].ExtRefNbr) == false)
                            {
                                list[i].StubCntr = 1;
                                graph.APPaymentList.Cache.PersistUpdated(list[i]);
                                graph.APPaymentList.Cache.Persisted(false);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        PXProcessing <APPayment> .SetError(i, e);
                    }
                    docs.Add(null);
                }
            }
            if (successed)
            {
                APDocumentRelease.ReleaseDoc(docs, true);
            }

            numbers.Sort();
            for (int i = numbers.Count - 1; i >= 0; i--)
            {
                PaymentMethodAccount det = PXSelect <PaymentMethodAccount, Where <PaymentMethodAccount.cashAccountID, Equal <Required <PaymentMethodAccount.cashAccountID> >, And <PaymentMethodAccount.paymentMethodID, Equal <Required <PaymentMethodAccount.paymentMethodID> > > > > .Select(graph, list[0].CashAccountID, list[0].PaymentMethodID);

                string lastnumber = AutoNumberAttribute.NextNumber(numbers[i], stubs[numbers[i]] - 1);

                if (string.Equals(lastnumber, det.APLastRefNbr))
                {
                    det.APLastRefNbr = AutoNumberAttribute.NextNumber(det.APLastRefNbr, -stubs[numbers[i]]);
                    graph.cashaccountdetail.Cache.PersistUpdated(det);
                    graph.cashaccountdetail.Cache.Persisted(false);
                }
            }

            if (failed)
            {
                throw new PXException(GL.Messages.DocumentsNotReleased);
            }
        }
示例#22
0
        protected virtual void ProcessPaymentFilter_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
        {
            bool SuggestNextNumber   = false;
            ProcessPaymentFilter row = (ProcessPaymentFilter)e.Row;

            PXUIFieldAttribute.SetVisible <ProcessPaymentFilter.curyID>(sender, null, PXAccess.FeatureInstalled <FeaturesSet.multicurrency>());

            if (e.Row != null && cashaccountdetail.Current != null && (!Equals(cashaccountdetail.Current.CashAccountID, row.PayAccountID) || !Equals(cashaccountdetail.Current.PaymentMethodID, row.PayTypeID)))
            {
                cashaccountdetail.Current = null;
                SuggestNextNumber         = true;
            }

            if (e.Row != null && paymenttype.Current != null && (!Equals(paymenttype.Current.PaymentMethodID, row.PayTypeID)))
            {
                paymenttype.Current = null;
            }

            if (e.Row != null && string.IsNullOrEmpty(row.NextCheckNbr))
            {
                SuggestNextNumber = true;
            }

            PXUIFieldAttribute.SetVisible <ProcessPaymentFilter.nextCheckNbr>(sender, null, true);

            if (e.Row == null)
            {
                return;
            }

            if (cashaccountdetail.Current != null && true == cashaccountdetail.Current.ARAutoNextNbr && SuggestNextNumber)
            {
                row.NextCheckNbr = string.IsNullOrEmpty(cashaccountdetail.Current.ARLastRefNbr) == false?AutoNumberAttribute.NextNumber(cashaccountdetail.Current.ARLastRefNbr) : string.Empty;
            }

            sender.RaiseExceptionHandling <ProcessPaymentFilter.payTypeID>(e.Row, row.PayTypeID,
                                                                           paymenttype.Current != null && true != PXCache <PaymentMethod> .GetExtension <PaymentMethodExt>(paymenttype.Current).ARCreateBatchPayment
                ? new PXSetPropertyException(AP.Messages.PaymentTypeNoPrintCheck, PXErrorLevel.Warning)
                : null);

            sender.RaiseExceptionHandling <ProcessPaymentFilter.nextCheckNbr>(e.Row, row.NextCheckNbr,
                                                                              paymenttype.Current != null && paymenttype.Current.PrintOrExport == true && String.IsNullOrEmpty(row.NextCheckNbr)
                ? new PXSetPropertyException(AP.Messages.NextCheckNumberIsRequiredForProcessing, PXErrorLevel.Warning)
                : !string.IsNullOrEmpty(row.NextCheckNbr) && !AutoNumberAttribute.CanNextNumber(row.NextCheckNbr)
                    ? new PXSetPropertyException(AP.Messages.NextCheckNumberCanNotBeInc, PXErrorLevel.Warning)
                    : null);

            if (/*HttpContext.Current != null && */ Filter.Current.BranchID != PXAccess.GetBranchID())
            {
                Filter.Current.BranchID = PXAccess.GetBranchID();
            }

            ProcessPaymentFilter filter = Filter.Current;
            PaymentMethod        pt     = paymenttype.Current;

            ARPaymentList.SetProcessTooltip(Messages.Process);
            ARPaymentList.SetProcessAllTooltip(Messages.ProcessAll);
            ARPaymentList.SetProcessDelegate(
                delegate(List <ARPayment> list)
            {
                var graph = CreateInstance <ARProcessPayment>();
                graph.ProcessPayments(list, filter, pt);
            }
                );
        }
示例#23
0
        public virtual void GenerateProc(Schedule schedule, short times, DateTime runDate)
        {
            string lastBatchNbr = "0000000000";
            long   lastInfoID   = -1;

            IEnumerable <ScheduleDet> occurrences = new Scheduler(this).MakeSchedule(schedule, times, runDate);

            using (PXTransactionScope ts = new PXTransactionScope())
            {
                foreach (ScheduleDet occurrence in occurrences)
                {
                    foreach (BatchNew scheduledBatch in PXSelect <
                                 BatchNew,
                                 Where <
                                     BatchNew.scheduleID, Equal <Optional <Schedule.scheduleID> >,
                                     And <BatchNew.scheduled, Equal <boolTrue> > > >
                             .Select(this, schedule.ScheduleID))
                    {
                        BatchNew copy = PXCache <BatchNew> .CreateCopy(scheduledBatch);

                        copy.OrigBatchNbr = copy.BatchNbr;
                        copy.OrigModule   = copy.Module;
                        copy.CuryInfoID   = null;
                        copy.NumberCode   = "GLREC";
                        copy.NoteID       = null;

                        CurrencyInfo info = (CurrencyInfo)PXSelect <
                            CurrencyInfo,
                            Where <CurrencyInfo.curyInfoID, Equal <Required <CurrencyInfo.curyInfoID> > > >
                                            .Select(this, scheduledBatch.CuryInfoID);

                        if (info != null)
                        {
                            CurrencyInfo infocopy = PXCache <CurrencyInfo> .CreateCopy(info);

                            infocopy.CuryInfoID = lastInfoID;
                            copy.CuryInfoID     = lastInfoID;

                            CuryInfo_Created.Cache.Insert(infocopy);
                        }

                        copy.Posted          = false;
                        copy.Released        = false;
                        copy.Status          = BatchStatus.Balanced;
                        copy.Scheduled       = false;
                        copy.AutoReverseCopy = false;

                        copy.DateEntered = occurrence.ScheduledDate;

                        FinPeriod finPeriod =
                            FinPeriodRepository.GetFinPeriodByMasterPeriodID(PXAccess.GetParentOrganizationID(copy.BranchID), occurrence.ScheduledPeriod)
                            .GetValueOrRaiseError();
                        copy.FinPeriodID  = finPeriod.FinPeriodID;
                        copy.TranPeriodID = null;

                        copy.BatchNbr    = lastBatchNbr;
                        copy.RefBatchNbr = lastBatchNbr;

                        lastBatchNbr = AutoNumberAttribute.NextNumber(lastBatchNbr);
                        lastInfoID--;

                        copy = (BatchNew)Batch_Created.Cache.Insert(copy);

                        CurrencyInfoAttribute.SetEffectiveDate <Batch.dateEntered>(Batch_Created.Cache, new PXFieldUpdatedEventArgs(copy, null, false));
                        PXNoteAttribute.CopyNoteAndFiles(Caches[typeof(BatchNew)], scheduledBatch, Batch_Created.Cache, copy);

                        foreach (GLTranNew scheduledBatchTransaction in PXSelect <
                                     GLTranNew,
                                     Where <
                                         GLTranNew.module, Equal <Required <GLTranNew.module> >,
                                         And <GLTranNew.batchNbr, Equal <Required <GLTranNew.batchNbr> > > > >
                                 .Select(this, scheduledBatch.Module, scheduledBatch.BatchNbr))
                        {
                            GLTranNew transactionCopy = PXCache <GLTranNew> .CreateCopy(scheduledBatchTransaction);

                            transactionCopy.OrigBatchNbr = transactionCopy.BatchNbr;
                            transactionCopy.OrigModule   = transactionCopy.Module;
                            transactionCopy.BatchNbr     = copy.BatchNbr;
                            transactionCopy.RefBatchNbr  = copy.RefBatchNbr;
                            transactionCopy.CuryInfoID   = copy.CuryInfoID;
                            transactionCopy.CATranID     = null;
                            transactionCopy.NoteID       = null;

                            transactionCopy.TranDate = occurrence.ScheduledDate;
                            FinPeriodIDAttribute.SetPeriodsByMaster <GLTranNew.finPeriodID>(Tran_Created.Cache, transactionCopy, occurrence.ScheduledPeriod);

                            transactionCopy = Tran_Created.Cache.Insert(transactionCopy) as GLTranNew;
                            PXNoteAttribute.CopyNoteAndFiles(Tran_Created.Cache, scheduledBatchTransaction, Tran_Created.Cache, transactionCopy);
                        }
                    }

                    schedule.LastRunDate = occurrence.ScheduledDate;
                    Running_Schedule.Cache.Update(schedule);
                }

                Running_Schedule.Cache.Persist(PXDBOperation.Update);

                Batch_Created.Cache.Persist(PXDBOperation.Insert);
                Batch_Created.Cache.Persist(PXDBOperation.Update);

                foreach (GLTranNew createdTransaction in Tran_Created.Cache.Inserted)
                {
                    foreach (BatchNew createdBatch in Batch_Created.Cache.Cached)
                    {
                        if (object.Equals(createdBatch.RefBatchNbr, createdTransaction.RefBatchNbr))
                        {
                            createdTransaction.BatchNbr   = createdBatch.BatchNbr;
                            createdTransaction.CuryInfoID = createdBatch.CuryInfoID;

                            if (!string.IsNullOrEmpty(createdBatch.RefNbr))
                            {
                                createdTransaction.RefNbr = createdBatch.RefNbr;
                            }

                            break;
                        }
                    }
                }

                Tran_Created.Cache.Normalize();

                Tran_Created.Cache.Persist(PXDBOperation.Insert);
                Tran_Created.Cache.Persist(PXDBOperation.Update);
                Caches[typeof(CA.CADailySummary)].Persist(PXDBOperation.Insert);

                ts.Complete(this);
            }

            Running_Schedule.Cache.Persisted(false);
            Batch_Created.Cache.Persisted(false);
            Tran_Created.Cache.Persisted(false);
            Caches[typeof(CA.CADailySummary)].Persisted(false);
        }
示例#24
0
        public static void AssignNumbers(APPaymentEntry pe, APPayment doc, ref string NextCheckNbr, bool skipStubs)
        {
            pe.RowPersisting.RemoveHandler <APAdjust>(pe.APAdjust_RowPersisting);
            pe.Clear(PXClearOption.PreserveTimeStamp);
            pe.Document.Current = (APPayment)pe.Document.Search <APPayment.refNbr>(doc.RefNbr, doc.DocType);
            if (String.IsNullOrEmpty(NextCheckNbr) == false)
            {
                if (String.IsNullOrEmpty(pe.Document.Current.ExtRefNbr))
                {
                    pe.Document.Current.StubCntr  = 1;
                    pe.Document.Current.BillCntr  = 0;
                    pe.Document.Current.ExtRefNbr = NextCheckNbr;
                    if (String.IsNullOrEmpty(NextCheckNbr))
                    {
                        throw new PXException(Messages.NextCheckNumberIsRequiredForProcessing);
                    }

                    if (pe.Document.Current.DocType == APDocType.QuickCheck && pe.Document.Current.CuryOrigDocAmt <= 0m)
                    {
                        throw new PXException(Messages.ZeroCheck_CannotPrint);
                    }

                    if (!skipStubs)
                    {
                        short j = 0;
                        foreach (PXResult <APAdjust> res in pe.Adjustments_print.Select())
                        {
                            pe.Document.Current.BillCntr++;

                            APAdjust             adj = (APAdjust)res;
                            PaymentMethod        pt  = pe.paymenttype.Select();
                            PaymentMethodAccount det = pe.cashaccountdetail.Select();
                            if (j > pt.APStubLines - 1)
                            {
                                //AssignCheckNumber only for first StubLines in check, other/all lines will be printed on remittance report
                                if (pt.APPrintRemittance == true)
                                {
                                    adj.StubNbr = null;
                                    pe.Adjustments.Cache.Update(adj);
                                    continue;
                                }
                                NextCheckNbr = AutoNumberAttribute.NextNumber(NextCheckNbr);
                                pe.Document.Current.StubCntr++;
                                j = 0;
                            }
                            adj.StubNbr = NextCheckNbr;
                            pe.Adjustments.Cache.Update(adj);
                            det.APLastRefNbr = NextCheckNbr;
                            pe.cashaccountdetail.Update(det);
                            j++;
                        }
                    }
                    NextCheckNbr = AutoNumberAttribute.NextNumber(NextCheckNbr);
                    pe.Document.Current.Printed          = true;
                    pe.Document.Current.Hold             = false;
                    pe.Document.Current.UpdateNextNumber = true;
                    pe.Document.Update(pe.Document.Current);
                }
                else
                {
                    if (pe.Document.Current.Printed != true || pe.Document.Current.Hold != false)
                    {
                        pe.Document.Current.Printed = true;
                        pe.Document.Current.Hold    = false;
                        pe.Document.Update(pe.Document.Current);
                    }
                }
            }
            else
            {
                PaymentMethod        method = pe.paymenttype.Select();
                PaymentMethodAccount det    = pe.cashaccountdetail.Select();
                //if (method != null && (method.PrintOrExport == false || det.APAutoNextNbr == true))
                {
                    if (pe.Document.Current.DocType == APDocType.QuickCheck && pe.Document.Current.CuryOrigDocAmt <= 0m)
                    {
                        throw new PXException(Messages.ZeroCheck_CannotPrint);
                    }

                    pe.Document.Current.StubCntr  = 1;
                    pe.Document.Current.BillCntr  = 0;
                    pe.Document.Current.ExtRefNbr = doc.ExtRefNbr;
                    if (!skipStubs)
                    {
                        foreach (PXResult <APAdjust> res in pe.Adjustments_print.Select())
                        {
                            pe.Document.Current.BillCntr++;

                            APAdjust adj = (APAdjust)res;
                            adj.StubNbr = doc.ExtRefNbr;
                            pe.Adjustments.Cache.Update(adj);
                        }
                    }
                    pe.Document.Current.Printed = true;
                    pe.Document.Current.Hold    = false;
                    pe.Document.Update(pe.Document.Current);
                }
            }
        }