예제 #1
0
        public override void Handle(Post post)
        {
            if (!post.HasXData || !post.XData.Displayed)
            {
                StringBuilder sb         = new StringBuilder();
                BindScope     boundScope = new BindScope(Report, post);

                if (!String.IsNullOrEmpty(ReportTitle))
                {
                    if (FirstReportTitle)
                    {
                        FirstReportTitle = false;
                    }
                    else
                    {
                        sb.AppendLine();
                    }

                    ValueScope valScope         = new ValueScope(boundScope, Value.StringValue(ReportTitle));
                    Format     groupTitleFormat = new Format(Report.GroupTitleFormatHandler.Str());

                    sb.Append(groupTitleFormat.Calc(valScope));

                    ReportTitle = string.Empty;
                }

                if (PrependFormat != null)
                {
                    sb.AppendFormat(StringExtensions.GetWidthAlignFormatString(PrependWidth), PrependFormat.Calc(boundScope));
                }

                if (LastXact != post.Xact)
                {
                    if (LastXact != null)
                    {
                        BindScope xactScope = new BindScope(Report, LastXact);
                        if (BetweenFormat != null)      // DM - in the original code, between_format is called w/o instantiating and returns nothing
                        {
                            sb.Append(BetweenFormat.Calc(xactScope));
                        }
                    }
                    sb.Append(FirstLineFormat.Calc(boundScope));
                    LastXact = post.Xact;
                }
                else if (LastPost != null && LastPost.GetDate() != post.GetDate())
                {
                    sb.Append(FirstLineFormat.Calc(boundScope));
                }
                else
                {
                    sb.Append(NextLineFormat.Calc(boundScope));
                }

                post.XData.Displayed = true;
                LastPost             = post;

                Report.OutputStream.Write(sb.ToString());
            }
        }
예제 #2
0
        /// <summary>
        /// Ported from void posts_to_org_table::operator()(post_t& post)
        /// </summary>
        public override void Handle(Post post)
        {
            if (!post.HasXData || !post.XData.Displayed)
            {
                StringBuilder sb = new StringBuilder();

                BindScope boundScope = new BindScope(Report, post);

                if (!HeaderPrinted)
                {
                    sb.AppendLine("|Date|Code|Payee|X|Account|Amount|Total|Note|");
                    sb.AppendLine("|-|");
                    sb.AppendLine("|||<20>|||<r>|<r>|<20>|");
                    HeaderPrinted = true;
                }

                if (!String.IsNullOrEmpty(ReportTitle))
                {
                    if (FirstReportTitle)
                    {
                        FirstReportTitle = false;
                    }
                    else
                    {
                        sb.AppendLine();
                    }

                    ValueScope valScope         = new ValueScope(boundScope, Value.StringValue(ReportTitle));
                    Format     groupTitleFormat = new Format(Report.GroupTitleFormatHandler.Str());

                    sb.AppendLine("|-|");
                    sb.Append("|" + groupTitleFormat.Calc(valScope));
                    sb.AppendLine("|-|");

                    ReportTitle = String.Empty;
                }

                if (PrependFormat != null)
                {
                    sb.Append("|" + PrependFormat.Calc(boundScope));
                }

                if (LastXact != post.Xact)
                {
                    sb.Append(FirstLineFormat.Calc(boundScope));
                    LastXact = post.Xact;
                }
                else if (LastPost != null && LastPost.GetDate() != post.GetDate())
                {
                    sb.Append(FirstLineFormat.Calc(boundScope));
                }
                else
                {
                    sb.Append(NextLineFormat.Calc(boundScope));
                }

                Value amt = new Expr("display_amount").Calc(boundScope).Simplified();
                Value tot = new Expr("display_total").Calc(boundScope).Simplified();

                if (amt.Type == ValueTypeEnum.Balance || tot.Type == ValueTypeEnum.Balance)
                {
                    Balance amtBal = amt.AsBalance;
                    Balance totBal = tot.AsBalance;

                    var  i     = amtBal.Amounts.GetIterator();
                    var  j     = totBal.Amounts.GetIterator();
                    bool first = true;

                    while (!i.IsEnd || !j.IsEnd)
                    {
                        if (first)
                        {
                            first = false;
                            if (!i.IsEnd)
                            {
                                i.MoveNext();
                            }
                            if (!j.IsEnd)
                            {
                                j.MoveNext();
                            }
                        }
                        else
                        {
                            SymbolScope callScope = new SymbolScope(boundScope);
                            bool        assigned  = false;

                            if (!i.IsEnd)
                            {
                                if (i.Current.Value != null)
                                {
                                    Logger.Current.Debug(DebugOrgNextAmount, () => String.Format("next_amount = {0}", i.Current.Value));
                                    callScope.Define(SymbolKindEnum.FUNCTION, "next_amount", ExprOp.WrapValue(Value.Get(i.Current.Value)));
                                    i.MoveNext();
                                    assigned = true;
                                }
                                else
                                {
                                    callScope.Define(SymbolKindEnum.FUNCTION, "next_amount", ExprOp.WrapValue(Value.StringValue(String.Empty)));
                                    i.MoveNext();
                                }
                            }
                            else
                            {
                                callScope.Define(SymbolKindEnum.FUNCTION, "next_amount", ExprOp.WrapValue(Value.StringValue(String.Empty)));
                            }

                            if (!j.IsEnd)
                            {
                                if (j.Current.Value != null)
                                {
                                    Logger.Current.Debug(DebugOrgNextTotal, () => String.Format("next_total = {0}", j.Current.Value));
                                    callScope.Define(SymbolKindEnum.FUNCTION, "next_total", ExprOp.WrapValue(Value.Get(j.Current.Value)));
                                    j.MoveNext();
                                    Logger.Current.Debug(DebugOrgNextTotal, () => String.Format("2.next_total = {0}", callScope.Lookup(SymbolKindEnum.FUNCTION, "next_total").AsValue));
                                    assigned = true;
                                }
                                else
                                {
                                    callScope.Define(SymbolKindEnum.FUNCTION, "next_total", ExprOp.WrapValue(Value.StringValue(String.Empty)));
                                    j.MoveNext();
                                }
                            }
                            else
                            {
                                callScope.Define(SymbolKindEnum.FUNCTION, "next_total", ExprOp.WrapValue(Value.StringValue(String.Empty)));
                            }

                            if (assigned)
                            {
                                AmountLinesFormat.MarkUncomplited();
                                sb.Append(AmountLinesFormat.Calc(callScope));
                            }
                        }
                    }
                }

                post.XData.Displayed = true;
                LastPost             = post;

                Report.OutputStream.Write(sb.ToString());
            }
        }