Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement corporate pricing into invoice items #546

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/invoice_items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ def destroy

private
def ii_params
params.require(:invoice_item).permit(:memo, :category, :price, :line_no)
params.require(:invoice_item).permit(:memo, :category, :price, :corporate, :line_no)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rename this to corporate_price to be more specific.

end
end
4 changes: 2 additions & 2 deletions app/models/invoice_item.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class InvoiceItem < ApplicationRecord
validates_presence_of :memo, :category, :price
validates_presence_of :memo, :category, :price, :corporate
validates_inclusion_of :category, :in => InvoiceLine::Invoice_Categories
validates_numericality_of :price
validates_numericality_of :price, :corporate
end
4 changes: 4 additions & 0 deletions app/views/invoice_items/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
<td class="subheading"><%= f.label :price %>:</td>
<td><%= f.text_field :price %></td>
</tr>
<tr>
<td class="subheading"><%= f.label :corporate %>:</td>
<td><%= f.text_field :corporate %></td>
</tr>
<tr>
<td></td>
<td><%= f.submit %></td>
Expand Down
2 changes: 2 additions & 0 deletions app/views/invoice_items/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<th>Memo</th>
<th>Category</th>
<th>Price</th>
<th>Corporate</th>
<% if can? :update, InvoiceItem %>
<th></th>
<% end %>
Expand All @@ -18,6 +19,7 @@
<td><%= item.memo %></td>
<td><%= item.category %></td>
<td><%= number_to_currency item.price %></td>
<td><%= number_to_currency item.corporate %></td>
<% if can? :update, item %>
<td><%= link_to 'Edit', edit_invoice_item_url(item) %></td>
<% end %>
Expand Down
6 changes: 5 additions & 1 deletion app/views/invoices/_invoice_line_fields.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
<option></option>

<% InvoiceItem.all.each do |item| %>
<option data-memo="<%= item.memo %>" data-category="<%= item.category %>" data-price="<%= item.price %>"><%= item.memo %></option>
<% if @invoice.payment_type == "Oracle" %>
<option data-memo="<%= item.memo %>" data-category="<%= item.category %>" data-price="<%= item.corporate %>"><%= item.memo %></option>
<% else %>
<option data-memo="<%= item.memo %>" data-category="<%= item.category %>" data-price="<%= item.price %>"><%= item.memo %></option>
<% end %>
Comment on lines +11 to +15
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not certain if this is the best way to detect corporate pricing. In a lot of cases you won't have an Oracle string at first, and there have been cases where you have an Oracle string but it goes to a student org. I don't think we want to cause people to input incorrect data/omit data simply to switch pricing.

It would probably be better to have a separate checkbox implemented only in JavaScript (that switches the select boxes). However, I think you can do this a slightly different way. See other comments.

<% end %>
</select>
</td>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class ChangeInvoiceItemPriceToFloat < ActiveRecord::Migration[6.1]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is missing the float migration and new column.

def change
end
end
5 changes: 3 additions & 2 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.