Skip to content

Commit

Permalink
Merge pull request #604 from sparc-request/sj-invoiced_notes
Browse files Browse the repository at this point in the history
SJ - Invoice Toggle Notes
  • Loading branch information
Stuart-Johnson committed Nov 12, 2019
2 parents 4e51d9b + b703aa8 commit b8cc047
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
6 changes: 4 additions & 2 deletions app/assets/javascripts/study_level_activities.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ $ ->
# Line Item Bindings

$(document).on 'change', 'input.invoice_toggle', ->
data = invoiced: $(this).prop('checked')
invoiced = $(this).prop('checked')
fulfillment_id = $(this).data('id')
$.ajax
type: 'PUT'
url: "/fulfillments/toggle_invoiced/#{fulfillment_id}"
data: data
data:
fulfillment:
invoiced: invoiced

$(document).on 'click', ".otf_service_new", ->
protocol_id = $('#protocol_id').val()
Expand Down
10 changes: 6 additions & 4 deletions app/controllers/fulfillments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ def update
end

def toggle_invoiced
@fulfillment.update_attributes(invoiced: params[:invoiced])
persist_original_attributes_to_track_changes
@fulfillment.update_attributes(invoiced: fulfillment_params[:invoiced])
detect_changes_and_create_notes
end

def destroy
Expand All @@ -90,7 +92,7 @@ def persist_original_attributes_to_track_changes
end

def detect_changes_and_create_notes
tracked_fields = [:fulfilled_at, :account_number, :quantity, :performer_id]
tracked_fields = [:fulfilled_at, :account_number, :quantity, :performer_id, :invoiced]
tracked_fields.each do |field|
current_field = @original_attributes[field.to_s]
new_field = fulfillment_params[field]
Expand Down Expand Up @@ -141,10 +143,10 @@ def update_components_and_create_notes(action='update')
end

def fulfillment_params
params.require(:fulfillment).permit(:line_item_id, :fulfilled_at, :quantity, :performer_id)
params.require(:fulfillment).permit(:line_item_id, :fulfilled_at, :quantity, :performer_id, :invoiced)
end

def find_fulfillment
@fulfillment = Fulfillment.find params[:id]
@fulfillment = Fulfillment.find(params[:id])
end
end
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ en:
fulfilled_at: "Fulfillment Date changed to "
quantity: "Quantity changed to "
performer_id: "Performed By changed to "
invoiced: "Invoiced changed to "
no_components: "Fulfillment Has No Components"
performed_by: "Performed By"
qty_type: "Quantity Type"
Expand Down

0 comments on commit b8cc047

Please sign in to comment.