Beispiel #1
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);
                    }
                }
            }
        }
        /// <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);
                }
            }
        }
Beispiel #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);
        }
		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);
				}
			}
		}
Beispiel #5
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;
            }
        }