Skip to content

Commit 04f69d7

Browse files
Feat: Allow Invoice Items to have Notes (#604)
Historically, "invoice items" were the presets that could be applied when creating an invoice. They've fell out of favor, but we still generate massively templated invoices. This PR adds "notes" to invoice items, such that when a preset is used, the memo is autofilled. We regularly use memos like this for labor quoting and other packages. Co-authored-by: Perry Naseck <4472083+DaAwesomeP@users.noreply.github.com>
1 parent 59ee7f5 commit 04f69d7

7 files changed

Lines changed: 26 additions & 4 deletions

File tree

app/controllers/invoice_items_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@ def destroy
4545

4646
private
4747
def ii_params
48-
params.require(:invoice_item).permit(:memo, :category, :price, :line_no)
48+
params.require(:invoice_item).permit(:memo, :category, :price, :notes, :line_no)
4949
end
5050
end

app/javascript/src/invoices.coffee

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ $ ->
1717
window.chooseLinePreset = (id) ->
1818
if $("#invoice-line-preset-" + id).val() != ""
1919
selected = $("#invoice-line-preset-" + id + " option:selected").first()
20+
if(selected.data('notes'))
21+
showNotes(id)
2022
$("#invoice_invoice_lines_attributes_" + id + "_category").val(selected.data('category'))
2123
$("#invoice_invoice_lines_attributes_" + id + "_memo").val(selected.data('memo'))
24+
$("#invoice_invoice_lines_attributes_" + id + "_notes").val(selected.data('notes'))
2225
$("#invoice_invoice_lines_attributes_" + id + "_quantity").val("1")
2326
$("#invoice_invoice_lines_attributes_" + id + "_price").val(selected.data('price'))
2427

@@ -32,6 +35,13 @@ window.toggleNotes = (id) ->
3235
note.css("display","none")
3336
link.html("V")
3437

38+
window.showNotes = (id) ->
39+
note = $("#notes" + id)
40+
link = $("#notesToggle" + id)
41+
if note.css("display") == "none"
42+
note.css("display","block")
43+
link.html("^")
44+
3545
window.indexList = () ->
3646
$('input.index').each( (i) ->
3747
$(this).val(i))
@@ -46,4 +56,4 @@ $ ->
4656
$("a.replace_field").click ->
4757
new_id = new Date().getTime()
4858
regexp = new RegExp("new_" + $(this).data("association"), "g")
49-
$("#" + $(this).data("repid")).html($(this).data("content").replace(regexp, new_id))
59+
$("#" + $(this).data("repid")).html($(this).data("content").replace(regexp, new_id))

app/views/invoice_items/_form.html.erb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
<td class="subheading"><%= f.label :price %>:</td>
2424
<td><%= f.text_field :price %></td>
2525
</tr>
26+
<tr>
27+
<td class="subheading"><%= f.label :notes %>:</td>
28+
<td><%= f.text_area :notes, :size => "35x3" %></td>
29+
</tr>
2630
<tr>
2731
<td></td>
2832
<td><%= f.submit %></td>

app/views/invoice_items/index.html.erb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<th>Memo</th>
66
<th>Category</th>
77
<th>Price</th>
8+
<th>Notes</th>
89
<% if can? :update, InvoiceItem %>
910
<th></th>
1011
<% end %>
@@ -18,6 +19,7 @@
1819
<td><%= item.memo %></td>
1920
<td><%= item.category %></td>
2021
<td><%= number_to_currency item.price %></td>
22+
<td><%= simple_format item.notes %></td>
2123
<% if can? :update, item %>
2224
<td><%= link_to 'Edit', edit_invoice_item_url(item) %></td>
2325
<% end %>

app/views/invoices/_invoice_line_fields.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<option></option>
99

1010
<% InvoiceItem.all.each do |item| %>
11-
<option data-memo="<%= item.memo %>" data-category="<%= item.category %>" data-price="<%= item.price %>"><%= item.memo %></option>
11+
<option data-memo="<%= item.memo %>" data-notes="<%= item.notes %>" data-category="<%= item.category %>" data-price="<%= item.price %>"><%= item.memo %></option>
1212
<% end %>
1313
</select>
1414
</td>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AddNotesToInvoiceItems < ActiveRecord::Migration[6.1]
2+
def change
3+
add_column :invoice_items, :notes, :text
4+
end
5+
end

db/schema.rb

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)