Class: YDIM::Factory
- Inherits:
-
Object
- Object
- YDIM::Factory
- Defined in:
- lib/ydim/factory.rb
Instance Method Summary collapse
- #create_autoinvoice(debitor) {|invoice| ... } ⇒ Object
- #create_invoice(debitor) {|invoice| ... } ⇒ Object
- #generate_invoice(autoinvoice) ⇒ Object
-
#initialize(serv) ⇒ Factory
constructor
A new instance of Factory.
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
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
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 |