Module: Magelex

Defined in:
lib/magelex.rb,
lib/magelex/version.rb,
lib/magelex/tax_guess.rb,
lib/magelex/lexware_csv.rb,
lib/magelex/magento_csv.rb,
lib/magelex/lexware_bill.rb,
lib/magelex/bill_modifier.rb,
lib/magelex/magento_mysql.rb,
lib/magelex/lexware_account.rb

Defined Under Namespace

Modules: AccountNumber, BillModifier, LexwareCSV, MagentoCSV, MagentoMYSQL, TaxGuess Classes: LexwareBill

Constant Summary collapse

VERSION =
"0.1.5".freeze

Class Method Summary collapse

Class Method Details

.loggerObject



13
14
15
# File 'lib/magelex.rb', line 13

def self.logger
  @logger ||= Logger.new STDERR
end

.logger=(logger) ⇒ Object



16
17
18
# File 'lib/magelex.rb', line 16

def self.logger= logger
  @logger = logger
end

.process_file(in_file, out_file, options) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/magelex.rb', line 20

def self.process_file in_file, out_file, options
  bills_export = []
  # Import/Read file.
  bills = Magelex::MagentoCSV.read in_file
  bills.each do |bill|
    if !bill.complete?
      Magelex.logger.info("Skip order #{bill.order_nr} (incomplete: #{bill.status})")
    else # complete!
      Magelex::BillModifier.process bill
      if !bill.check
        if bill.discount_7 != 0 || bill.discount_19 != 0
          Magelex.logger.info("#{bill.order_nr}: discounted")
        end
        Magelex.logger.info("Skip order #{bill.order_nr}#{bill.swiss? ? ' (swiss)' : ''} #{bill.has_problems ? ' (broken item)': '' }")
        Magelex.logger.info("  (totals do not match [#{bill.check_diff}] #{bill.total} != "\
                            "(0: #{bill.total_0} + 7: #{bill.total_7} "\
                            "+ 19: #{bill.total_19} "\
                            "= #{bill.total_0 + bill.total_7 + bill.total_19})")
        if bill.discount_19 != 0 || bill.discount_7 != 0
          Magelex.logger.info(bill.inspect)
        end
      else
        if bill.swiss?
          Magelex.logger.info("#{bill.order_nr}: swiss")
        end
        if bill.discount_7 != 0 || bill.discount_19 != 0
          Magelex.logger.info("#{bill.order_nr}: discounted")
        end
        Magelex.logger.debug("Handle #{bill.order_nr}")
        bills_export << bill
      end
    end
  end

  # Fix dates via database.
  if !options[:skipdb]
    begin
      Magelex.logger.info("Fetching dates from magento mysql.")
      Magelex::MagentoMYSQL.update_dates YAML.load_file('magelex.conf'), bills_export
    rescue => e
      Magelex.logger.error("Could not connect to MySQL database, exiting.")
      Magelex.logger.error(e.inspect)
      exit 2
    end
  else
    Magelex.logger.debug("Skip fetching dates from magento mysql.")
  end

  # Export/Write to file
  if File.exist?(out_file)
    Magelex.logger.error("Output file #{out_file} exists already, exiting.")
    exit 3
  end
  Magelex.logger.info("Writing to #{out_file}")
  # TODO want STDOUT
  Magelex::LexwareCSV.write out_file, bills_export
end