Class: YDIM::Html::View::InvoiceList

Inherits:
HtmlGrid::List show all
Defined in:
lib/ydim/html/view/invoices.rb

Direct Known Subclasses

AutoInvoiceList

Constant Summary collapse

COMPONENTS =
{
  [0,0]    =>  :unique_id,
  [1,0]    =>  :name,
  [2,0]    =>  :email,
  [3,0]    =>  :description,
  [4,0]    =>  :formatted_date,
  [5,0]    =>  :toggle_payment_received,
  [6,0]    =>  :total_netto,
  [7,0]    =>  :total_brutto,
  [8,0]    =>  :currency,
  [9,0]    =>  :send_invoice,
  [10,0] =>  :pdf,
  [11,0] =>  :toggle_deleted,
}
CSS_ID =
'invoices'
CSS_MAP =
{
  [6,0,2]  => 'right',
}
SORT_DEFAULT =
nil

Constants inherited from HtmlGrid::List

HtmlGrid::List::STRIPED_BG

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from HtmlGrid::List

ajax_inputs

Class Method Details



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ydim/html/view/invoices.rb', line 32

def debitor_links(*names)
  names.each { |name|
    define_method(name) { |model|
      link = HtmlGrid::Link.new(name, model, @session, self)
      link.href = @lookandfeel._event_url(:debitor, 
                                          {:unique_id => model.debitor_id})
      str = model.send("debitor_#{name}").to_s
      if(str.length > 30)
        str = str[0,27] << '...'
      end
      link.value = str
      link
    }
  }
end

.toggle(name, on, off) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/ydim/html/view/invoices.rb', line 47

def toggle(name, on, off)
  define_method("toggle_#{name}") { |model|
    current = model.send(name)
    key = current ? off : on
    link = HtmlGrid::Link.new(key, model, @session, self)
    args = {
      :unique_id       => model.unique_id,
      name             =>  !current,
    }
    url = @lookandfeel._event_url("ajax_#{css_id}", args)
    link.href = "javascript: reload_list('#{css_id}', '#{url}')"
    link
  }
end

Instance Method Details

#column_position(key, offset) ⇒ Object



101
102
103
104
# File 'lib/ydim/html/view/invoices.rb', line 101

def column_position(key, offset)
  pos = components.key(key)
  [pos.at(0) + offset.at(0), pos.at(1) + offset.at(1)]
end


70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/ydim/html/view/invoices.rb', line 70

def compose_footer(offset)
  garbage = false
  netto = 0.0
  brutto = 0.0
  total = @model.each { |invoice|
    garbage = true if(invoice.deleted)
    netto += invoice.total_netto
    brutto += invoice.total_brutto
  }
  if(garbage)
    button = HtmlGrid::Button.new(:collect_garbage, @model, @session, self)
    url = @lookandfeel._event_url(:ajax_collect_garbage)
    button.set_attribute('onClick', "reload_list('invoices', '#{url}');")
    @grid.add(button, *offset)
    @grid.set_colspan(*offset)
  else
    label = HtmlGrid::LabelText.new(:total, @model, @session, self)
    lpos = column_position(:name, offset)
    @grid.add(label, *lpos)
    @grid.set_colspan(*lpos.push(2))
    total(:total_netto, netto, offset)
    total(:total_brutto, brutto, offset)
    lpos = column_position(:currency, offset)
    @grid.add(Html.config.currency, *lpos)
  end
end

#formatted_date(model) ⇒ Object



105
106
107
108
109
110
111
# File 'lib/ydim/html/view/invoices.rb', line 105

def formatted_date(model)
  if(date = model.date)
    link = date(model)
    link.value = @lookandfeel.format_date(date)
    link
  end
end

#pdf(model) ⇒ Object



112
113
114
115
116
# File 'lib/ydim/html/view/invoices.rb', line 112

def pdf(model)
  link = HtmlGrid::Link.new(:pdf, model, @session, self)
  link.href = @lookandfeel._event_url(:pdf, {:unique_id => model.unique_id})
  link
end

#row_css(model, bg_flag) ⇒ Object



67
68
69
# File 'lib/ydim/html/view/invoices.rb', line 67

def row_css(model, bg_flag)
   [super, model.status].compact.join(' ')
end

#send_invoice(model) ⇒ Object



117
118
119
120
121
122
123
124
# File 'lib/ydim/html/view/invoices.rb', line 117

def send_invoice(model)
  if(model.status == 'is_due')
    link = HtmlGrid::Link.new(:send_invoice, model, @session, self)
    link.href = @lookandfeel._event_url(:send_invoice, 
                                        {:unique_id => model.unique_id})
    link
  end
end

#total(key, total, offset) ⇒ Object



96
97
98
99
100
# File 'lib/ydim/html/view/invoices.rb', line 96

def total(key, total, offset)
  tpos = column_position(key, offset)
  @grid.add(number_format(format(total)), *tpos)
  @grid.add_attribute('class', 'right total', *tpos)
end