fetch inviting data when select case_no

This commit is contained in:
chiu 2020-08-05 15:54:33 +08:00
parent c9157e9132
commit 128bc5c158
5 changed files with 41 additions and 7 deletions

View File

@ -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',

View File

@ -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

View File

@ -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

View File

@ -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)
})
}
})
})
})
</script>

View File

@ -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