# File lib/Helpers/AccountBankStatement.rb, line 50
          def import_invoice(invoices, options={},*args)
            o = {:date => false, :journals => []}.merge(options)
            if o[:date] :
                o[:date] = Date.parse(str=o[:date]).to_s
            else
                o[:date] = Date.today.to_s
            end

            # Parse the given journal ids if provided
            journal_ids=[]
            o[:journals].each do |journal|
              journal_ids.push journal.id
            end
            invoice_move_line_ids=[]
            inv_total=0.0
            self.balance_start=inv_total

            # # For each invoices, add the right account.move.line and compute total
            invoices.each do |inv|
              unless inv.class  == AccountInvoice :
                raise "!!! --- HELPER ERROR :import_invoice received a #{inv.class.to_s} instead of AccountInvoice" 
              end
              # Take the move ids from concerned invoice
              # TODO add journal support and (journal_ids.include? move_line.journal_id or journal_ids == []
              # TODO : Debug the problem of undefined method `[]' for nil:NilClass (NoMethodError)
              # pp inv.move_id.line_id
              #       inv.move_id.line_id.each do |move_line|
              #         
              #         # if move_line.reconcile_id == false
              #         if move_line.account_id.reconcile == true
              #           invoice_move_line_ids.push move_line.id
              #         end
              #       end
              
              inv.move_id.line_id.each do |move_line|
                if (not move_line.reconcile_id) && move_line.account_id.reconcile
                  invoice_move_line_ids.push move_line.id
                  inv_total = inv_total + move_line.amount_currency
                end
              end
            end
            # Save the start and end values
            self.balance_end_real=inv_total
            self.save
            unless self.class  == AccountBankStatement :
              raise "!!! --- HELPER ERROR :import_invoice received a #{self.class.to_s} instead of AccountBankStatement" 
            end

            # Call the wizard
            wizard = self.old_wizard_step('populate_statement_from_inv')
            # Set the wizard with given values
            step_dict = wizard.datas.merge({:date=>o[:date]})
            step_dict=step_dict.merge({:journal_id=> [[[],[],journal_ids]]})
            # Search the invoices and update values
            res=wizard.go(step_dict)
            step_dict=res.datas.merge(step_dict)
            # Update the step_dict with invoice we want
            step_dict=step_dict.merge({:lines=> [[[],[],invoice_move_line_ids]]})
            # Ask to populate the statement with given invoice linked account move
            res=wizard.finish(step_dict)
            # step_dict = step_dict.merge({:writeoff_acc_id => @journal.default_debit_account_id.id, :writeoff_journal_id=>@journal.id})
            # return res
          end