diff --git a/app/controllers/admin/venue_management_contracts_controller.rb b/app/controllers/admin/venue_management_contracts_controller.rb index 5333c0e..de86848 100644 --- a/app/controllers/admin/venue_management_contracts_controller.rb +++ b/app/controllers/admin/venue_management_contracts_controller.rb @@ -9,7 +9,17 @@ class Admin::VenueManagementContractsController < Admin::VenueAdminController super @app_title = 'venue_management' end - + def fetch_inviting + invitings = VenueManagementInviting.where(id: params[:id]) + data = {} + if !invitings.first.nil? + key = [:early_rent,:operation_rent,:royalty,:house_tax_payer,:land_tax_payer] + invitings.pluck(*key)[0].each_with_index do |v,i| + data[key[i]] = v + end + end + render :json => data + end def index @table_fields = [ 'venue_management.title', diff --git a/app/models/venue_management_contract.rb b/app/models/venue_management_contract.rb index 3f0d680..fc6cbf1 100644 --- a/app/models/venue_management_contract.rb +++ b/app/models/venue_management_contract.rb @@ -54,9 +54,7 @@ class VenueManagementContract belongs_to :venue_management_main belongs_to :venue_management_inviting include VenueLinkFile - before_save do - org_contract = VenueManagementContract.find(self.id) rescue nil - inviting = VenueManagementInviting.find(self.venue_management_inviting_id) rescue nil + def update_inviting(inviting,check_inviting,org_contract=nil,save_flag=true) if !inviting.nil? %i(case_no publish_times start_date end_date close_date bid_date evaluation_date contractor_manager bid_result details).each do |attr_| self[attr_] = inviting.send(attr_) rescue nil @@ -67,7 +65,7 @@ class VenueManagementContract update_flag = true if !org_contract.nil? && org_contract.venue_management_inviting_id == self.venue_management_inviting_id %i(early_rent operation_rent royalty house_tax_payer land_tax_payer).each do |attr_| - if self[attr_] != (inviting.send(attr_) rescue nil) + if self[attr_] != (check_inviting.send(attr_) rescue nil) update_flag = false end end @@ -77,5 +75,13 @@ class VenueManagementContract self[attr_] = (inviting.send(attr_) rescue nil) end end + if save_flag + self.save + end + end + before_save do + org_contract = VenueManagementContract.find(self.id) rescue nil + inviting = VenueManagementInviting.find(self.venue_management_inviting_id) rescue nil + update_inviting(inviting,inviting,org_contract,false) end end diff --git a/app/models/venue_management_inviting.rb b/app/models/venue_management_inviting.rb index 0afe740..b7f2acc 100644 --- a/app/models/venue_management_inviting.rb +++ b/app/models/venue_management_inviting.rb @@ -32,8 +32,9 @@ class VenueManagementInviting include VenueLinkFile before_save do contracts = self.venue_management_contracts + org_inviting = VenueManagementInviting.find(self.id) rescue nil contracts.each do |contract| - contract.save + contract.update_inviting(self,org_inviting,contract) end end end diff --git a/app/views/admin/venue_management_contracts/_form.html.erb b/app/views/admin/venue_management_contracts/_form.html.erb index a5ca4d7..54194db 100644 --- a/app/views/admin/venue_management_contracts/_form.html.erb +++ b/app/views/admin/venue_management_contracts/_form.html.erb @@ -228,5 +228,18 @@ $('#renewal_deadline').hide() } }) + $('#venue_management_contract_venue_management_inviting_id').change(function(){ + $.ajax({ + url : "/admin/venue_management_contracts/fetch_inviting", + data : {"id" : $(this).val()}, + dataType : "json", + type : "post", + success : function(data){ + $.each(data,function(k,v){ + $('*[name="venue_management_contract['+k+']"]').val(v) + }) + } + }) + }) }) \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 3684580..db4c654 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -27,7 +27,11 @@ Rails.application.routes.draw do resources :venue_management_item_contents resources :venue_management_invitings resources :venue_management_memorabilias - resources :venue_management_contracts + resources :venue_management_contracts do + collection do + post 'fetch_inviting' + end + end end resources :venue_managements do