Skip to content

Commit

Permalink
Merge 896e788 into fd44d2d
Browse files Browse the repository at this point in the history
  • Loading branch information
jgreben committed Aug 23, 2018
2 parents fd44d2d + 896e788 commit 872ec99
Show file tree
Hide file tree
Showing 20 changed files with 390 additions and 131 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ Metrics/MethodLength:
Metrics/AbcSize:
Max: 27

Metrics/ParameterLists:
Max: 6

Style/PercentLiteralDelimiters:
Enabled: false

Expand Down
48 changes: 45 additions & 3 deletions app/controllers/edi_lins_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,52 @@ def allow_nobib
end
end

def update
@message = EdiLin.make_updates(params[:vendors], params[:invoice_number], params[:invoice_line_number])
flash[@message[0].to_sym] = @message[1]
def fix_duplicate_barcode
respond_to do |format|
format.js # modal window: fix_duplicate_barcode.js.erb
end
end

def show
@edi_lin = EdiLin.where(barcode_num: params[:barcode_num])
end

def index
@edi_lin = EdiLin.where(barcode_num: params[:barcode_num])
if @edi_lin.size.zero?
redirect_to(edi_invoices_menu_path, flash: { warning: "Barcode #{params[:barcode_num]} does not exist "\
'as a barcode in the EDI_LIN table.' })
elsif @edi_lin.size < 2
redirect_to(edi_invoices_menu_path, flash: { warning: "Barcode #{params[:barcode_num]} is not a duplicate. "\
'It only appears once in the EDI_LIN table.' })
else
redirect_to "/edi_lins/show/#{params[:barcode_num]}"
end
end

def edit
@edi_lin = EdiLin.where(vend_id: params[:vend_id],
doc_num: params[:doc_num],
edi_lin_num: params[:edi_lin_num],
edi_sublin_count: params[:edi_sublin_count],
barcode_num: params[:barcode_num])
end

def update_edi_lin
@edi_lin_result = EdiLin.update_edi_lin(params[:vendors], params[:invoice_number], params[:invoice_line_number])
flash[@edi_lin_result[0].to_sym] = @edi_lin_result[1]

redirect_to edi_invoices_menu_path
end

def update_barcode
@barcode_result = EdiLin.update_barcode(params[:vend_id],
params[:doc_num],
params[:edi_lin_num],
params[:edi_sublin_count],
params[:old_barcode],
params[:new_barcode])
flash[@barcode_result[0].to_sym] = @barcode_result[1]
redirect_to edi_invoices_menu_path
end
end
14 changes: 13 additions & 1 deletion app/models/edi_lin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def self.vendors
select(:vend_id).uniq
end

def self.make_updates(vendor, invoice, line)
def self.update_edi_lin(vendor, invoice, line)
edi_lin = where('vend_id = ? AND doc_num = ? AND edi_lin_num = ? AND edi_sublin_count = 0', vendor, invoice, line)
if ids_match?(EdiSumrzBib.id(edi_lin.vend_unique_id), edi_lin.vend_unique_id)
['error', 'Cannot set this invoice line to "noBib." This invoice line has a bib match in Symphony. '\
Expand All @@ -24,11 +24,23 @@ def self.make_updates(vendor, invoice, line)
end
end

# We need to skip model validations on update because we can only retrieve the correct row using a 'where' finder
# and only 'update_all' will work on this finding method.
# rubocop:disable Rails/SkipsModelValidations
def self.make_nobib(nobib_id)
row = EdiLin.where(vend_unique_id: nobib_id).pluck(primary_key.to_sym).first
EdiLin.where(row_id => row).update_all(vend_unique_id: "#{nobib_id}noBib")
end

def self.update_barcode(vendor, invoice, line, subline, old_barcode, new_barcode)
row = EdiLin.where(vend_id: vendor,
doc_num: invoice,
edi_lin_num: line,
edi_sublin_count: subline,
barcode_num: old_barcode).pluck(primary_key.to_sym).first
EdiLin.where(row_id => row).update_all(barcode_num: new_barcode)
['notice', "EDI Line for #{vendor}, #{invoice}, line #{line} updated with new barcode: #{new_barcode}"]
end
# rubocop:enable Rails/SkipsModelValidations

def self.vend_unique_id
Expand Down
3 changes: 2 additions & 1 deletion app/views/edi_invoices/_edi_updates_menu.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
'data-toggle' => "modal", 'data-target' => '#new-modal-window' %></li>
<li><%= link_to "Allow a \"noBib\"", edi_lins_allow_nobib_path, :remote => true,
'data-toggle' => "modal", 'data-target' => '#new-modal-window' %></li>
<li><%= link_to "Fix duplicate barcode", edi_invoices_fix_duplicate_barcode_path %></li>
<li><%= link_to "Fix duplicate barcode", edi_lins_fix_duplicate_barcode_path, :remote => true,
'data-toggle' => "modal", 'data-target' => '#new-modal-window' %></li>
</div>
29 changes: 29 additions & 0 deletions app/views/edi_lins/_fix_duplicate_barcode.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="fixDuplicateBarcode">Fix duplicate barcode</h3>
</div>
<div class="modal-body">
<%= form_tag({controller: 'edi_lins', action: 'index'}, method: 'get') do %>
<div class="div-table">
<div class="div-table-body">
<div class="div-table-row">
<div class="div-table-cell">
Enter barcode
</div>
</div>
<div class="div-table-row">
<div class="div-table-cell">
<%= text_field_tag 'barcode_num' %>
</div>
</div>
</div>
<div class="btn-group">
<button class='btn btn-md btn-default btn-full' data-dismiss="modal" aria-hidden="true">Cancel</button>
</div>
&nbsp;
<div class="btn-group">
<%= submit_tag 'Next', class: 'btn btn-md btn-primary btn-full' %>
</div>
</div>
<% end %>
</div>
32 changes: 32 additions & 0 deletions app/views/edi_lins/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<div class="home-page-section">
<h1>Edit EDI line with duplicate barcodes</h1>
<table class="table table-striped">
<thead>
<tr>
<th>Vendor</th>
<th>Invoice Num</th>
<th>Line Num</th>
<th>Barcode</th>
</tr>
</thead>
<tbody>
<% @edi_lin.each do |edi, index | %>
<tr class='<%= cycle("odd", "even") %>'>
<td><%= edi.vend_id %></td>
<td><%= edi.doc_num %></td>
<td><%= edi.edi_lin_num.present? ? edi.edi_lin_num.to_i : '' %></td>
<td><%= text_field_tag('new_barcode', '', placeholder: edi.barcode_num.present? ? edi.barcode_num.to_i : '', onblur: "$('#barcode#{index}').data('bc', $(this).val())") %></td>
<td>
<%= link_to 'Change this barcode', {controller: 'edi_lins', action: 'update_barcode'}, id: "barcode#{index}", onclick: "window.location = '/edi_lins/update_barcode?new_barcode=' + $('#barcode#{index}').data('bc') + '&vend_id=#{edi.vend_id}&doc_num=#{edi.doc_num}&edi_lin_num=#{edi.edi_lin_num}&edi_sublin_count=#{edi.edi_sublin_count}&old_barcode=#{edi.barcode_num}'; return true" , class: 'btn btn-primary' %>
</td>
</tr>
<% end %>
</tbody>
</table>
<div class="btn-group">
<%= main_menu_button %>
</div>
<div class="btn-group">
<%= edi_menu_button %>
</div>
</div>
1 change: 1 addition & 0 deletions app/views/edi_lins/fix_duplicate_barcode.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$("#new-modal-window").html("<%= escape_javascript(render 'fix_duplicate_barcode') %>");
31 changes: 31 additions & 0 deletions app/views/edi_lins/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<div class="home-page-section">
<h1>EDI lines with duplicate barcodes</h1>
<table class="table table-striped">
<thead>
<tr>
<th></th>
<th>Vendor</th>
<th>Invoice Num</th>
<th>Line Num</th>
<th>Barcode</th>
</tr>
</thead>
<tbody>
<% @edi_lin.each do |edi| %>
<tr class='<%= cycle("odd", "even") %>'>
<td><%= radio_button_tag('edi_lin', 'edit', false, onclick: "window.location = '/edi_lins/show/#{edi.barcode_num.present? ? edi.barcode_num.to_i : 'no_barcode'}'") %></td>
<td><%= edi.vend_id %></td>
<td><%= edi.doc_num %></td>
<td><%= edi.edi_lin_num.present? ? edi.edi_lin_num.to_i : '' %></td>
<td><%= edi.barcode_num.present? ? edi.barcode_num.to_i : '' %></td>
</tr>
<% end %>
</tbody>
</table>
<div class="btn-group">
<%= main_menu_button %>
</div>
<div class="btn-group">
<%= edi_menu_button %>
</div>
</div>
38 changes: 38 additions & 0 deletions app/views/edi_lins/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<div class="home-page-section">
<h1>EDI lines with duplicate barcodes</h1>
<table class="table table-striped">
<thead>
<tr>
<th></th>
<th>Vendor</th>
<th>Invoice Num</th>
<th>Line Num</th>
<th>Barcode</th>
</tr>
</thead>
<tbody>
<% @edi_lin.each do |edi| %>
<tr class='<%= cycle("odd", "even") %>'>
<td>
<%= radio_button_tag('edi_lin', 'edit', false, onclick: "window.location = '/edi_lins/edit/"\
"#{edi.vend_id},"\
"#{edi.doc_num},"\
"#{edi.edi_lin_num.present? ? edi.edi_lin_num.to_i : ''},"\
"#{edi.edi_sublin_count.present? ? edi.edi_sublin_count.to_i : ''},"\
"#{edi.barcode_num.present? ? edi.barcode_num.to_i : ''}'") %>
</td>
<td><%= edi.vend_id %></td>
<td><%= edi.doc_num %></td>
<td><%= edi.edi_lin_num.present? ? edi.edi_lin_num.to_i : '' %></td>
<td><%= edi.barcode_num.present? ? edi.barcode_num.to_i : '' %></td>
</tr>
<% end %>
</tbody>
</table>
<div class="btn-group">
<%= main_menu_button %>
</div>
<div class="btn-group">
<%= edi_menu_button %>
</div>
</div>
11 changes: 6 additions & 5 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@
get 'edi_invoices/invoice_exclude' => 'edi_invoices#invoice_exclude'
get 'edi_invoices/change_invoice_line' => 'edi_invoices#change_invoice_line'
get 'edi_lins/allow_nobib' => 'edi_lins#allow_nobib'
get 'edi_lins/update' => 'edi_lins#update'
get 'edi_invoices/update' => 'edi_invoices#update'
get 'edi_invoices/fix_duplicate_barcode' => 'edi_invoices#fix_duplicate_barcode'
get 'edi_lins/allow_nobib' => 'edi_lins#allow_nobib'
get 'edi_lins/update' => 'edi_lins#update'
get 'edi_lins/edit/:vend_id,:doc_num,:edi_lin_num,:edi_sublin_count,:barcode_num' => 'edi_lins#edit'
get 'edi_lins/fix_duplicate_barcode' => 'edi_lins#fix_duplicate_barcode'
get 'edi_lins/index' => 'edi_lins#index'
get 'edi_lins/update_edi_lin' => 'edi_lins#update_edi_lin'
get 'edi_lins/update_barcode' => 'edi_lins#update_barcode'
get 'edi_lins/show/:barcode_num' => 'edi_lins#show'

get 'management_reports' => 'management_reports#index'

Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20180727193130_add_columns_to_edi_lin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddColumnsToEdiLin < ActiveRecord::Migration
def change
add_column :edi_lin, :barcode_num, :integer, limit: 6
end
end
7 changes: 4 additions & 3 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20180725220246) do
ActiveRecord::Schema.define(version: 20180727193130) do

create_table "authorized_user", force: :cascade do |t|
t.string "user_id"
Expand Down Expand Up @@ -159,8 +159,9 @@
t.integer "edi_lin_num"
t.integer "edi_sublin_count"
t.string "vend_unique_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "barcode_num", limit: 6
end

create_table "edi_sumrz_bib", force: :cascade do |t|
Expand Down
2 changes: 1 addition & 1 deletion db/seeds/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ def make_table(model, file, keys)
end

make_table(EdiSumrzBib, 'edi_sumrz_bib.csv', %w[vend_code id001 edi_ckey load_date active_record])
make_table(EdiLin, 'edi_lin.csv', %w[doc_num vend_id edi_lin_num edi_sublin_count vend_unique_id])
make_table(EdiErrorReport, 'edi_error_report.csv', %w[run type error err_lvl])
make_table(EdiInvPiece, 'edi_inv_piece.csv', %w[edi_vend_id edi_doc_num])
make_table(EdiInvoice, 'edi_invoice.csv', %w[edi_doc_num edi_vend_id edi_vend_inv_date todo uni_inv_cre_date
edi_total_pieces edi_msg_id edi_msg_typ edi_msg_seg uni_vend_key uni_accrue_or_pay_tax edi_stanfd_account uni_inv_lib
uni_inv_key uni_inv_num edi_invc_total uni_invc_total edi_total_postage edi_total_freight edi_total_handling edi_total_insurance
edi_cur_code edi_total_tax edi_exchg_rate edi_tax_rate edi_total_pieces])
make_table(EdiLin, 'edi_lin.csv', %w[doc_num vend_id edi_lin_num edi_sublin_count vend_unique_id barcode_num])
make_table(EdiInvLine, 'edi_inv_line.csv', %w[tbl_row_num edi_vend_id edi_doc_num edi_line_num edi_fund edi_po_number edi_line_net edi_line_gross todo])
make_table(UnicornPolicy, 'unicorn_policies.csv', %w[type policy_num name description shadowed destination])
make_table(ExpendituresFunds, 'expenditures_funds.csv', %w[fund_id fund_name_key old_fund_id min_pay_date max_pay_date is_endow inv_lib])
Expand Down
2 changes: 1 addition & 1 deletion db/seeds/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ def make_table(model, file, keys)
end

make_table(EdiSumrzBib, 'edi_sumrz_bib.csv', %w[vend_code id001 edi_ckey load_date active_record])
make_table(EdiLin, 'edi_lin.csv', %w[doc_num vend_id edi_lin_num edi_sublin_count vend_unique_id])
make_table(EdiInvPiece, 'edi_inv_piece.csv', %w[edi_vend_id edi_doc_num])
make_table(EdiInvoice, 'edi_invoice.csv', %w[edi_doc_num edi_vend_id edi_vend_inv_date todo uni_inv_cre_date
edi_total_pieces edi_msg_id edi_msg_typ edi_msg_seg uni_vend_key uni_accrue_or_pay_tax edi_stanfd_account uni_inv_lib
uni_inv_key uni_inv_num edi_invc_total uni_invc_total edi_total_postage edi_total_freight edi_total_handling edi_total_insurance
edi_cur_code edi_total_tax edi_exchg_rate edi_tax_rate edi_total_pieces])
make_table(EdiLin, 'edi_lin.csv', %w[doc_num vend_id edi_lin_num edi_sublin_count vend_unique_id barcode_num])

ExpendituresFyDate.destroy_all
dates = [
Expand Down
11 changes: 0 additions & 11 deletions spec/controllers/edi_invoices_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,4 @@
expect(response).to have_http_status(302)
end
end
let(:message) { get :update, vendors: 'AMALIV', invoice_number: '22222' }
describe 'update with actual table updates' do
before do
stub_current_user(FactoryBot.create(:authorized_user))
end
it 'notifies of possible changes to the table' do
controller.instance_variable_set(:@message, message)
expect(flash).to be_present
expect(response).to redirect_to edi_invoices_menu_path
end
end
end

0 comments on commit 872ec99

Please sign in to comment.