Class: YDIM::Html::State::AutoInvoice

Inherits:
Invoice
  • Object
show all
Includes:
AutoInvoiceKeys
Defined in:
lib/ydim/html/state/autoinvoice.rb

Constant Summary collapse

VIEW =
Html::View::AutoInvoice

Constants inherited from Global

Global::EVENT_MAP

Instance Attribute Summary

Attributes inherited from Invoice

#model

Attributes inherited from Global

#sort_reverse, #sortby

Instance Method Summary collapse

Methods included from AutoInvoiceKeys

#invoice_key, #invoice_keys, #invoice_mandatory

Methods inherited from Invoice

#_do_update, #ajax_create_item, #ajax_delete_item, #ajax_item, #init, #pdf, #send_invoice, #update

Methods included from InvoiceKeys

#invoice_key, #invoice_keys, #invoice_mandatory

Methods inherited from Global

#_create_invoice, #autoinvoice, #create_autoinvoice, #create_debitor, #create_invoice, #debitor, #invoice, #logout, #pdf, #send_invoice

Instance Method Details

#_do_update_invoice(input) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/ydim/html/state/autoinvoice.rb', line 78

def _do_update_invoice(input)
  ptrn = %r{<invoice>.*</invoice>}m
  if(body = input[:reminder_body])
    test = body.gsub(ptrn, "").strip
    if(test.empty?)
      input.store(:reminder_body, nil)
    else
      input.store(:reminder_body, body.gsub(ptrn, format_invoice))
    end
  end
  super(input)
end

#ajax_invoiceObject



35
36
37
38
# File 'lib/ydim/html/state/autoinvoice.rb', line 35

def ajax_invoice
  _do_update
  AjaxAutoInvoice.new(@session, @model)
end

#format_invoiceObject



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
# File 'lib/ydim/html/state/autoinvoice.rb', line 39

def format_invoice
  lnf = @session.lookandfeel
  total = lnf.lookup(:total_netto)
  item_widths = [total.length]
  qty_widths = []
  float = false
  @model.items.each do |item|
    item_widths.push item.text.length
    qty = item.quantity
    qty_widths.push qty.to_i.to_s.length
    float ||= (qty.to_i != qty.to_f)
  end
  item_width = item_widths.max.to_i.next
  qty_width = qty_widths.max.to_i
  total_width = ("%3.2f" % @model.total_netto).length
  fmt = if float
          qty_width += 3
          "%#{qty_width}.2f x %-#{item_width}s %s %#{total_width}.2f\n"
        else
          "%#{qty_width}i x %-#{item_width}s %s %#{total_width}.2f\n"
        end
  invoice = "<invoice>\n"
  currency = @model.currency
  @model.items.each { |item|
    invoice << sprintf(fmt, item.quantity.to_f, item.text,
                       currency, item.total_netto)
  }
  fmt = "%#{qty_width + 2}s %-#{item_width}s %s %#{total_width}.2f\n"
  invoice << sprintf(fmt, '', total,
                     currency, @model.total_netto)
  invoice << "</invoice>"
end

#generate_invoiceObject



71
72
73
74
75
76
77
# File 'lib/ydim/html/state/autoinvoice.rb', line 71

def generate_invoice
  _do_update
  if((id = @session.user_input(:unique_id)) \
     && @model.unique_id == id.to_i)
    Invoice.new(@session, @session.generate_invoice(id))
  end
end