def valid?
      @errors = []

      if !manual_journal_id.nil? && manual_journal_id !~ GUID_REGEX
        @errors << ['manual_journal_id', 'must be blank or a valid Xero GUID']
      end

      if narration.blank?
      	@errors << ['narration', "can't be blank"]
      end

      unless date
        @errors << ['date', "can't be blank"]
      end

      # Make sure all journal_items are valid.
      unless journal_lines.all? { | journal_line | journal_line.valid? }
        @errors << ['journal_lines', "at least one journal line invalid"]
      end

      # make sure there are at least 2 journal lines
      unless journal_lines.length > 1
      	@errors << ['journal_lines', "journal must contain at least two individual journal lines"]
      end

      if journal_lines.length > 100
      	@errors << ['journal_lines', "journal must contain less than one hundred journal lines"]
      end

      unless journal_lines.sum(&:line_amount).to_f == 0.0
      	@errors << ['journal_lines', "the total debits must be equal to total credits"]
      end

      @errors.size == 0
    end
def valid?
      @errors = []

      if !manual_journal_id.nil? && manual_journal_id !~ GUID_REGEX
        @errors << ['manual_journal_id', 'must be blank or a valid Xero GUID']
      end

      if narration.blank?
      	@errors << ['narration', "can't be blank"]
      end

      unless date
        @errors << ['date', "can't be blank"]
      end

      # Make sure all journal_items are valid.
      unless journal_lines.all? { | journal_line | journal_line.valid? }
        @errors << ['journal_lines', "at least one journal line invalid"]
      end

      # make sure there are at least 2 journal lines
      unless journal_lines.length > 1
      	@errors << ['journal_lines', "journal must contain at least two individual journal lines"]
      end

      if journal_lines.length > 100
      	@errors << ['journal_lines', "journal must contain less than one hundred journal lines"]
      end

      unless journal_lines.sum(&:line_amount).to_f == 0.0
      	@errors << ['journal_lines', "the total debits must be equal to total credits"]
      end

      @errors.size == 0
    end
Validate the ManualJournal record according to what will be valid by the gateway.

 Usage:
  manual_journal.valid?     # Returns true/false

  Additionally sets manual_journal.errors array to an array of field/error.