Ejemplo n.º 1
0
        public string GenerateXact()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(Times.TimesCommon.Current.FormatDate(NextDate, FormatTypeEnum.FMT_WRITTEN));
            NextDate = NextDate.AddDays(SixGen.Value());
            if (TruthGen.Value())
            {
                sb.Append('=');
                sb.Append(Times.TimesCommon.Current.FormatDate(NextAuxDate, FormatTypeEnum.FMT_WRITTEN));
                NextAuxDate = NextAuxDate.AddDays(SixGen.Value());
            }
            sb.Append(' ');

            sb.Append(GenerateState());
            sb.Append(GenerateCode());
            sb.Append(GeneratePayee());
            if (TruthGen.Value())
            {
                sb.Append(GenerateNote());
            }
            sb.AppendLine();

            int  count          = ThreeGen.Value() * 2;
            bool hasMustBalance = false;

            for (int i = 0; i < count; i++)
            {
                if (GeneratePost(sb))
                {
                    hasMustBalance = true;
                }
            }
            if (hasMustBalance)
            {
                GeneratePost(sb, true);
            }

            sb.AppendLine();

            return(sb.ToString());
        }
Ejemplo n.º 2
0
        public string GenerateCost(Value amount)
        {
            StringBuilder sb = new StringBuilder();

            if (TruthGen.Value())
            {
                sb.Append(" @ ");
            }
            else
            {
                sb.Append(" @@ ");
            }

            if (!String.IsNullOrEmpty(GenerateAmount(sb, amount, true, amount.AsAmount.Commodity.Symbol)))
            {
                return(sb.ToString());
            }
            else
            {
                return(String.Empty);
            }
        }
Ejemplo n.º 3
0
        public bool GeneratePost(StringBuilder sb, bool noAmount = false)
        {
            sb.Append("    ");
            bool mustBalance = GenerateAccount(sb, noAmount);

            sb.Append("  ");

            if (!noAmount)
            {
                Value amount = Value.Get(GenerateAmount(sb));
                if (TruthGen.Value())
                {
                    sb.Append(GenerateCost(amount));
                }
            }
            if (TruthGen.Value())
            {
                sb.Append(GenerateNote());
            }
            sb.AppendLine();

            return(mustBalance);
        }
Ejemplo n.º 4
0
        public string GenerateAmount(StringBuilder sbOut, Value notThisAmount = null, bool noNegative = false, string exclude = null)
        {
            StringBuilder sb = new StringBuilder();

            if (TruthGen.Value())
            {            // commodity goes in front
                sb.Append(GenerateCommodity(exclude));
                if (TruthGen.Value())
                {
                    sb.Append(' ');
                }
                if (noNegative || TruthGen.Value())
                {
                    sb.Append(PosNumberGen.Value().ToString("G15"));
                }
                else
                {
                    sb.Append(NegNumberGen.Value().ToString("G15"));
                }
            }
            else
            {
                if (noNegative || TruthGen.Value())
                {
                    sb.Append(PosNumberGen.Value().ToString("G15"));
                }
                else
                {
                    sb.Append(NegNumberGen.Value().ToString("G15"));
                }
                if (TruthGen.Value())
                {
                    sb.Append(' ');
                }
                sb.Append(GenerateCommodity(exclude));
            }

            // Possibly generate an annotized commodity, but make it rarer
            if (!noNegative && ThreeGen.Value() == 1)
            {
                if (ThreeGen.Value() == 1)
                {
                    sb.Append(" {");
                    GenerateAmount(sb, Value.Empty, true);
                    sb.Append('}');
                }
                if (SixGen.Value() == 1)
                {
                    sb.Append(" [");
                    sb.Append(GenerateDate());
                    sb.Append(']');
                }
                if (SixGen.Value() == 1)
                {
                    sb.Append(" (");
                    sb.Append(GenerateString(SixGen.Value()));
                    sb.Append(')');
                }
            }

            if (!Value.IsNullOrEmpty(notThisAmount) && Value.Get(sb.ToString()).AsAmount.Commodity == notThisAmount.AsAmount.Commodity)
            {
                return(String.Empty);
            }

            sbOut.Append(sb.ToString());

            return(sb.ToString());
        }