Skip to content

Commit

Permalink
Merge d16ec89 into bbcf76a
Browse files Browse the repository at this point in the history
  • Loading branch information
jgreben committed Aug 1, 2018
2 parents bbcf76a + d16ec89 commit 02cd621
Show file tree
Hide file tree
Showing 15 changed files with 490 additions and 207 deletions.
7 changes: 7 additions & 0 deletions app/controllers/edi_invoices_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ def index
@edi_invoice = apply_scopes(EdiInvoice).all
end

def update
@message = EdiInvoice.make_updates(params[:vendors], params[:invoice_number])
flash[@message[0].to_sym] = @message[1]

redirect_to edi_invoices_menu_path
end

def change_invoice_line
@edi_inv_line = EdiInvLine.where("todo = 'CreOrd'")
respond_to do |format|
Expand Down
4 changes: 4 additions & 0 deletions app/models/edi_inv_piece.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Model for EDI_INV_PIECE
class EdiInvPiece < ActiveRecord::Base
self.table_name = 'edi_inv_piece'
end
70 changes: 70 additions & 0 deletions app/models/edi_invoice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,76 @@ class EdiInvoice < ActiveRecord::Base
}

self.table_name = 'edi_invoice'
self.primary_keys = :edi_vend_id, :edi_doc_num

def self.make_updates(vendor, invoice)
@edi_invoice = where('edi_vend_id = ? AND edi_doc_num = ?', vendor, invoice)
if @edi_invoice.present?
if %w(CreInvc SKIP CreOrd Excld).include?(@edi_invoice.pluck(:todo)[0].to_s)
['error', "Invoice NOT excluded! #{@edi_invoice.edi_vend_id} invoice no. #{@edi_invoice.edi_doc_num} "\
'is already through EDI processing past the point of safe Exclusion via web form.']
else
update_edi_invoice
delete_edi_inv_line
delete_edi_piece
['warning', "#{@edi_invoice.edi_vend_id} invoice no. #{@edi_invoice.edi_doc_num} excluded from EDI processing"]
end
else
insert_edi_invoice(vendor, invoice)
['warning', "#{@edi_invoice.edi_vend_id} invoice no. #{@edi_invoice.edi_doc_num}, "\
'excluded from EDI processing']
end
end

def self.update_edi_invoice
edi_invoice = @edi_invoice.first
edi_invoice.todo = 'Excld'
edi_invoice.uni_vend_key = nil
edi_invoice.uni_accrue_or_pay_tax = nil
edi_invoice.edi_stanfd_account = nil
edi_invoice.uni_inv_lib = nil
edi_invoice.uni_inv_key = nil
edi_invoice.uni_inv_num.to_s << '<-Excld'
edi_invoice.edi_invc_total = 0
edi_invoice.uni_invc_total = 0
edi_invoice.edi_total_postage = 0
edi_invoice.edi_total_freight = 0
edi_invoice.edi_total_handling = 0
edi_invoice.edi_total_insurance = 0
edi_invoice.edi_cur_code = nil
edi_invoice.edi_total_tax = 0
edi_invoice.edi_exchg_rate = nil
edi_invoice.edi_tax_rate = nil
edi_invoice.edi_total_pieces = 0
edi_invoice.save
end

def self.delete_edi_inv_line
EdiInvLine.delete_all(['edi_doc_num = ? AND edi_vend_id = ?',
@edi_invoice.edi_doc_num,
@edi_invoice.edi_vend_id[0]])
end

def self.delete_edi_piece
EdiInvPiece.delete_all(['edi_doc_num = ? AND edi_vend_id = ?',
@edi_invoice.edi_doc_num,
@edi_invoice.edi_vend_id[0]])
end

def self.insert_edi_invoice(vendor, invoice)
excld = EdiInvoice.new
excld.edi_doc_num = invoice
excld.edi_vend_id = vendor
excld.edi_msg_id = 'Excld'
excld.edi_msg_typ = 'INVOIC'
excld.todo = 'Excld'
excld.edi_msg_seg = 'HDR'
excld.save
end

def self.edi_doc_num
pluck(:edi_doc_num)[0]
end

def self.edi_vend_id
distinct.pluck(:edi_vend_id)
Expand Down
19 changes: 16 additions & 3 deletions app/views/edi_invoices/_invoice_exclude.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,33 @@
<h3 id="excludeInvoice">Exclude an invoice</h3>
</div>
<div class="modal-body">
<%= form_tag({controller: 'edi_invoices', action: 'update'}, method: 'get') do %>
<div class="div-table">
<div class="div-table-body">
<div class="div-table-row">
<div class="div-table-cell">

1) Select a vendor
</div>
<div class="div-table-cell">

2) Enter an invoice number
</div>
</div>
<div class="div-table-row">
<div class="div-table-cell">
<%= select_tag 'vendors', options_for_select(@edi_invoice.edi_vend_id.compact, 'edi_vend_id') %>
</div>
<div class="div-table-cell">
<%= text_field_tag 'invoice_number' %>
</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>
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
get 'edi_invoices/menu' => 'edi_invoices#menu'
get 'edi_invoices/invoice_exclude' => 'edi_invoices#invoice_exclude'
get 'edi_invoices/change_invoice_line' => 'edi_invoices#change_invoice_line'
get 'edi_invoices/update' => 'edi_invoices#update'
get 'edi_invoices/allow_nobib' => 'edi_invoices#allow_nobib'
get 'edi_invoices/fix_duplicate_barcode' => 'edi_invoices#fix_duplicate_barcode'

Expand Down
10 changes: 10 additions & 0 deletions db/migrate/20180725205541_create_edi_inv_piece.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class CreateEdiInvPiece < ActiveRecord::Migration
def change
create_table :edi_inv_piece do |t|
t.string :edi_vend_id
t.string :edi_doc_num

t.timestamps null: false
end
end
end
23 changes: 23 additions & 0 deletions db/migrate/20180725220246_add_columns_to_edi_invoice.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class AddColumnsToEdiInvoice < ActiveRecord::Migration
def change
add_column :edi_invoice, :edi_msg_id, :string
add_column :edi_invoice, :edi_msg_typ, :string
add_column :edi_invoice, :edi_msg_seg, :string
add_column :edi_invoice, :uni_vend_key, :integer
add_column :edi_invoice, :uni_accrue_or_pay_tax, :string
add_column :edi_invoice, :edi_stanfd_account, :string
add_column :edi_invoice, :uni_inv_lib, :string
add_column :edi_invoice, :uni_inv_key, :integer
add_column :edi_invoice, :uni_inv_num, :string
add_column :edi_invoice, :edi_invc_total, :integer
add_column :edi_invoice, :uni_invc_total, :integer
add_column :edi_invoice, :edi_total_postage, :integer
add_column :edi_invoice, :edi_total_freight, :integer
add_column :edi_invoice, :edi_total_handling, :integer
add_column :edi_invoice, :edi_total_insurance, :integer
add_column :edi_invoice, :edi_cur_code, :string
add_column :edi_invoice, :edi_total_tax, :integer
add_column :edi_invoice, :edi_exchg_rate, :integer
add_column :edi_invoice, :edi_tax_rate, :integer
end
end
52 changes: 49 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: 20180712235601) do
ActiveRecord::Schema.define(version: 20180725220246) do

create_table "authorized_user", force: :cascade do |t|
t.string "user_id"
Expand Down Expand Up @@ -116,15 +116,61 @@
t.string "todo"
end

create_table "edi_inv_piece", force: :cascade do |t|
t.string "edi_vend_id"
t.string "edi_doc_num"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

create_table "edi_invoice", force: :cascade do |t|
t.string "edi_doc_num"
t.string "edi_vend_id"
t.datetime "edi_vend_inv_date"
t.string "todo"
t.datetime "uni_inv_cre_date"
t.integer "edi_total_pieces"
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.string "edi_msg_id"
t.string "edi_msg_typ"
t.string "edi_msg_seg"
t.integer "uni_vend_key"
t.string "uni_accrue_or_pay_tax"
t.string "edi_stanfd_account"
t.string "uni_inv_lib"
t.integer "uni_inv_key"
t.string "uni_inv_num"
t.integer "edi_invc_total"
t.integer "uni_invc_total"
t.integer "edi_total_postage"
t.integer "edi_total_freight"
t.integer "edi_total_handling"
t.integer "edi_total_insurance"
t.string "edi_cur_code"
t.integer "edi_total_tax"
t.integer "edi_exchg_rate"
t.integer "edi_tax_rate"
end

create_table "edi_lin", force: :cascade do |t|
t.string "doc_num"
t.string "vend_id"
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
end

create_table "edi_sumrz_bib", force: :cascade do |t|
t.string "vend_code"
t.string "id001"
t.integer "edi_ckey"
t.datetime "load_date"
t.integer "active_record"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

create_table "encumbrance_rpts", force: :cascade do |t|
Expand Down
114 changes: 27 additions & 87 deletions db/seeds/development.rb
Original file line number Diff line number Diff line change
@@ -1,87 +1,31 @@
require 'csv'

EdiErrorReport.destroy_all
keys = %w[run type error err_lvl]
csv_text = File.read(Rails.root.join('spec', 'fixtures', 'files', 'edi_error_report.csv'))
csv = CSV.parse(csv_text, headers: false)
csv.map { |a| Hash[keys.zip(a)] }
hash = csv.map { |a| Hash[keys.zip(a)] }
EdiErrorReport.create(hash)

EdiInvoice.destroy_all
keys = %w[edi_doc_num edi_vend_id edi_vend_inv_date todo uni_inv_cre_date edi_total_pieces]
csv_text = File.read(Rails.root.join('spec', 'fixtures', 'files', 'edi_invoice.csv'))
csv = CSV.parse(csv_text, headers: false)
csv.map { |a| Hash[keys.zip(a)] }
hash = csv.map { |a| Hash[keys.zip(a)] }
EdiInvoice.create(hash)

EdiInvLine.destroy_all
keys = %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]
csv_text = File.read(Rails.root.join('spec', 'fixtures', 'files', 'edi_inv_line.csv'))
csv = CSV.parse(csv_text, headers: false)
csv.map { |a| Hash[keys.zip(a)] }
hash = csv.map { |a| Hash[keys.zip(a)] }
EdiInvLine.create(hash)

UnicornPolicy.destroy_all
keys = %w[type policy_num name description shadowed destination]
csv_text = File.read(Rails.root.join('spec', 'fixtures', 'files', 'unicorn_policies.csv'))
csv = CSV.parse(csv_text, headers: false)
csv.map { |a| Hash[keys.zip(a)] }
hash = csv.map { |a| Hash[keys.zip(a)] }
UnicornPolicy.create(hash)

ExpendituresFunds.destroy_all
keys = %w[fund_id fund_name_key old_fund_id min_pay_date max_pay_date is_endow inv_lib]
csv_text = File.read(Rails.root.join('spec', 'fixtures', 'files', 'expenditures_funds.csv'))
csv = CSV.parse(csv_text, headers: false)
csv.map { |a| Hash[keys.zip(a)] }
hash = csv.map { |a| Hash[keys.zip(a)] }
ExpendituresFunds.create(hash)

ExpendituresPaydates.destroy_all
keys = ['pay_date']
csv_text = File.read(Rails.root.join('spec', 'fixtures', 'files', 'expenditures_paydates.csv'))
csv = CSV.parse(csv_text, headers: false)
csv.map { |a| Hash[keys.zip(a)] }
hash = csv.map { |a| Hash[keys.zip(a)] }
ExpendituresPaydates.create(hash)

UniLibsLocs.destroy_all
keys = %w[library home_loc]
csv_text = File.read(Rails.root.join('spec', 'fixtures', 'files', 'uni_libs_locs.csv'))
csv = CSV.parse(csv_text, headers: false)
csv.map { |a| Hash[keys.zip(a)] }
hash = csv.map { |a| Hash[keys.zip(a)] }
UniLibsLocs.create(hash)

ShelfSelectionItemType.destroy_all
keys = ['item_type']
csv_text = File.read(Rails.root.join('spec', 'fixtures', 'files', 'item_types.csv'))
csv = CSV.parse(csv_text, headers: false)
csv.map { |a| Hash[keys.zip(a)] }
hash = csv.map { |a| Hash[keys.zip(a)] }
ShelfSelectionItemType.create(hash)

ShelfSelItemCat1.destroy_all
keys = ['item_category1']
csv_text = File.read(Rails.root.join('spec', 'fixtures', 'files', 'item_cat1.csv'))
csv = CSV.parse(csv_text, headers: false)
csv.map { |a| Hash[keys.zip(a)] }
hash = csv.map { |a| Hash[keys.zip(a)] }
ShelfSelItemCat1.create(hash)

CirculationStatisticsReportFormat.destroy_all
keys = ['format']
csv_text = File.read(Rails.root.join('spec', 'fixtures', 'files', 'formats.csv'))
csv = CSV.parse(csv_text, headers: false)
csv.map { |a| Hash[keys.zip(a)] }
hash = csv.map { |a| Hash[keys.zip(a)] }
CirculationStatisticsReportFormat.create(hash)
def make_table(model, file, keys)
model.destroy_all
csv_text = File.read(Rails.root.join('spec', 'fixtures', 'files', file))
csv = CSV.parse(csv_text, headers: false)
csv.map { |a| Hash[keys.zip(a)] }
hash = csv.map { |a| Hash[keys.zip(a)] }
model.create(hash)
end

Expenditures.destroy_all
keys = %w[row_date review_date ta_inv_line_key ta_fund_code ta_fund_total_paid
make_table(EdiInvPiece, 'edi_inv_piece.csv', %w[edi_vend_id edi_doc_num])
# 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(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(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])
make_table(ExpendituresPaydates, 'expenditures_paydates.csv', ['pay_date'])
make_table(UniLibsLocs, 'uni_libs_locs.csv', %w[library home_loc])
make_table(ShelfSelectionItemType, 'item_types.csv', ['item_type'])
make_table(ShelfSelItemCat1, 'item_cat1.csv', ['item_category1'])
make_table(CirculationStatisticsReportFormat, 'formats.csv', ['format'])
make_table(Expenditures, 'expenditures.csv', %w[row_date review_date ta_inv_line_key ta_fund_code ta_fund_total_paid
ta_gl_code ta_ord_line_key ta_inv_key ta_date_2encina ta_encina_key ta_invoice_total_withtax
ta_tax_total ta_taxtype_flag ta_vend_inv_date ta_vend_inv_num ti_inv_lib ti_inv_line_note
ti_inv_line_num ti_inv_line_total_us ti_unicorn_inv_num ti_inv_line_type ti_inv_line_total_vendor
Expand All @@ -91,12 +35,7 @@
d2_hldc_type sc_lib sc_id sc_cat1 sc_cat2 or_create_date ca_title ca_author ca_year
ca_place ca_lang ca_pub260 cn_callnum vn_name_key fn_name_key fn_level1 fn_level2
fn_level3 fn_level4 fn_fund_key fg_funding_key fg_fundcyc_key ca_fmt ca_020 ca_022
ca_024 ca_series ca_962 cn_shlv_key ol_volume i_created_by i_modified_by ]
csv_text = File.read(Rails.root.join('spec', 'fixtures', 'files', 'expenditures.csv'))
csv = CSV.parse(csv_text, headers: false)
csv.map { |a| Hash[keys.zip(a)] }
hash = csv.map { |a| Hash[keys.zip(a)] }
Expenditures.create(hash)
ca_024 ca_series ca_962 cn_shlv_key ol_volume i_created_by i_modified_by ])

ExpendituresFyDate.destroy_all
dates = [
Expand Down Expand Up @@ -125,3 +64,4 @@
dates.each do |fy, min, max|
ExpendituresFyDate.create(fy: fy, min_paydate: min, max_paydate: max)
end

0 comments on commit 02cd621

Please sign in to comment.