Class: YDIM::Factory

Inherits:
Object
  • Object
show all
Defined in:
lib/ydim/factory.rb

Instance Method Summary collapse

Constructor Details

#initialize(serv) ⇒ Factory

Returns a new instance of Factory.



10
11
12
# File 'lib/ydim/factory.rb', line 10

def initialize(serv)
	@serv = serv
end

Instance Method Details

#create_autoinvoice(debitor) {|invoice| ... } ⇒ Object

Yields:

  • (invoice)


13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/ydim/factory.rb', line 13

def create_autoinvoice(debitor)
	id = @serv.id_server.next_id(:autoinvoice, 
                                 @serv.config.invoice_number_start)
	invoice = AutoInvoice.new(id)
	yield(invoice) if(block_given?)
    if debitor.foreign?
      invoice.suppress_vat = true
    end
	invoice.debitor = debitor
	debitor.autoinvoices.odba_store
	invoice
end

#create_invoice(debitor) {|invoice| ... } ⇒ Object

Yields:

  • (invoice)


25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ydim/factory.rb', line 25

def create_invoice(debitor)
	id = @serv.id_server.next_id(:invoice, @serv.config.invoice_number_start)
	invoice = Invoice.new(id)
	yield(invoice) if(block_given?)
	invoice.debitor = debitor
    if debitor.foreign?
      invoice.suppress_vat = true
    end
	debitor.invoices.odba_store
	invoice
end

#generate_invoice(autoinvoice) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/ydim/factory.rb', line 36

def generate_invoice(autoinvoice)
  create_invoice(autoinvoice.debitor) { |inv|
    date = autoinvoice.date || Date.today
    nextdate = autoinvoice.advance(date)
    inv.date = date
    inv.currency = autoinvoice.currency
    inv.description = sprintf("%s %s-%s", autoinvoice.description,
                              date.strftime("%d.%m.%Y"),
                              (nextdate - 1).strftime("%d.%m.%Y"))
    inv.precision = autoinvoice.precision
    inv.payment_period = autoinvoice.payment_period
    autoinvoice.items.each { |item|
      nitem = item.dup
      nitem.time = Time.now
      nitem.expiry_time = Time.local(nextdate.year, nextdate.month,
                                     nextdate.day)
      nitem.vat_rate = @serv.config.vat_rate
      inv.add_item(nitem)
    }
    autoinvoice.odba_store
  }
end