class YDIM::Html::State::AutoInvoice

Constants

VIEW

Public Instance Methods

_do_update_invoice(input) click to toggle source
Calls superclass method
# File lib/ydim/html/state/autoinvoice.rb, line 79
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_invoice() click to toggle source
# File lib/ydim/html/state/autoinvoice.rb, line 36
def ajax_invoice
  _do_update
  AjaxAutoInvoice.new(@session, @model)
end
format_invoice() click to toggle source
# File lib/ydim/html/state/autoinvoice.rb, line 40
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_invoice() click to toggle source
# File lib/ydim/html/state/autoinvoice.rb, line 72
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