const std = @import("std"); const row = @import("../row.zig"); const Posting = @import("Posting.zig"); const Transaction = @import("Transaction.zig"); const Comparison = @import("Comparison.zig"); const Error = Comparison.Error; date: row.Date, narration: []const u8, /// Exactly two, source first (M1-JRN-003). postings: [2]Posting, pub fn compare(self: Transaction, other: Transaction, at: Comparison) Error!void { if (!self.date.isSame(other.date)) { return at.differs("date differs: approved {f}, candidate {f}", .{ self.date, other.date }); } if (!std.mem.eql(u8, self.narration, other.narration)) { return at.textDiffers("narration", self.narration, other.narration); } for (self.postings, other.postings, 0..) |a, c, posting| { try a.compare(c, at.inPosting(posting)); } } /// The journal block for this transaction, each line newline-terminated: /// the only rendering a transaction has, so it is the one `{f}` gives. pub fn format(self: Transaction, writer: *std.Io.Writer) std.Io.Writer.Error!void { // M1-JRN-002: the parsed date in YYYY-MM-DD, then the narration. try writer.print("{f} {s}\n", .{ self.date, self.narration }); // M1-JRN-003: source first, then destination. for (self.postings) |posting| { try writer.print("{f}\n", .{posting}); } }