Add Contract Model & CRUD

This commit is contained in:
Leo Chen 2020-07-31 01:30:14 +08:00
parent 05cfa10a8e
commit 5ea12df38d
16 changed files with 507 additions and 12 deletions

View File

@ -0,0 +1,73 @@
# frozen_string_literal: true
class Admin::VenueManagementContractsController < OrbitAdminController
include Admin::VenueManagementsHelper
before_action ->(module_app = @app_title) { set_variables module_app }
before_action :set_venue_management_contract, only: [:edit, :update, :destroy]
def initialize
super
@app_title = 'venue_management'
end
def index
@table_fields = [
'venue_management.title',
'vm_contract.case_no',
'vm_contract.vendor',
'vm_contract.start_end',
'vm_contract.renewal_permission',
'vm_contract.note',
]
@contracts = VenueManagementContract.order(updated_at: :desc).page(params[:page]).per(10)
end
def new
@venue_management = VenueManagementMain.find(params[:id])
@venue_management_contract = @venue_management.venue_management_contracts.build
end
def create
@venue_management_contract = VenueManagementContract.new(venue_management_contract_params)
inviting = VenueManagementInviting.find_by(id: venue_management_contract_params[:venue_management_inviting_id])
assign_inviting_attrs(@venue_management_contract, inviting)
@venue_management_contract.save
redirect_to params['referer_url']
end
def edit
@venue_management = VenueManagementMain.find(@venue_management_contract.venue_management_main_id)
end
def update
inviting = VenueManagementInviting.find_by(id: venue_management_contract_params[:venue_management_inviting_id])
assign_inviting_attrs(@venue_management_contract, inviting)
@venue_management_contract.update_attributes(venue_management_contract_params)
redirect_to venue_management_contracts_admin_venue_management_path(@venue_management_contract.venue_management_main_id)
end
def destroy
@venue_management_main_id = @venue_management_contract.venue_management_main_id
@venue_management_contract.destroy
redirect_to venue_management_contracts_admin_venue_management_path(@venue_management_main_id)
end
private
def assign_inviting_attrs(contract, inviting)
%i(case_no publish_times start_date end_date close_date bid_date evaluation_date early_rent operation_rent royalty contractor_manager house_tax_payer land_tax_payer bid_result details).each do |attr|
contract[attr] = inviting.send(attr)
end
end
def set_venue_management_contract
@venue_management_contract = VenueManagementContract.find(params[:id])
end
def venue_management_contract_params
params.require(:venue_management_contract).permit!
end
end

View File

@ -4,7 +4,7 @@ class Admin::VenueManagementsController < OrbitAdminController
require 'axlsx'
helper Admin::VenueManagementsFieldHelper
before_action ->(module_app = @app_title) { set_variables module_app }
before_action :set_venue_management, only: [:edit, :set_write_off, :venue_management_signup, :destroy, :venue_management_invitings, :venue_management_memorabilias]
before_action :set_venue_management, only: [:edit, :set_write_off, :venue_management_signup, :destroy, :venue_management_invitings, :venue_management_memorabilias, :venue_management_contracts]
def initialize
super
@ -20,7 +20,15 @@ class Admin::VenueManagementsController < OrbitAdminController
def index
@categories = @module_app.categories.enabled
@filter_fields = filter_fields(@categories)
@table_fields = [:category, 'venue_management.title', 'venue_management.event_during', 'venue_management.signup_during', 'venue_management.signup_count', 'venue_management.inviting_hostory', 'venue_management.memorabilia','venue_management.export']
@table_fields = [ :category,
'venue_management.title',
'venue_management.event_during',
'venue_management.signup_during',
'venue_management.contract_history',
'venue_management.inviting_history',
'venue_management.memorabilia',
'venue_management.export'
]
if !params[:sort].blank?
if params[:sort] == 'event_during'
@ -263,6 +271,17 @@ class Admin::VenueManagementsController < OrbitAdminController
@memorabilias = @venue_management.venue_management_memorabilias.page(params[:page]).per(10)
end
def venue_management_contracts
@table_fields = [
'vm_contract.case_no',
'vm_contract.vendor',
'vm_contract.start_end',
'vm_contract.renewal_permission',
'vm_contract.note',
]
@contracts = @venue_management.venue_management_contracts.page(params[:page]).per(10)
end
private
def set_venue_management

View File

@ -0,0 +1,58 @@
# frozen_string_literal: true
require 'orbit_form_helper'
class VenueManagementContract
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::Enum
PAYERS = [ :school, :vendor ].freeze
BID_RESULTS = [ :failure, :abandoned, :qualified ].freeze
# Copy from Inviting
field :case_no, type: String
field :publish_times, type: Integer
field :start_date, type: Date, default: Time.now
field :end_date, type: Date
field :close_date, type: Date
field :bid_date, type: Date
field :evaluation_date, type: Date
field :early_rent, type: Integer
field :operation_rent, type: Integer
field :royalty, type: Integer
field :contractor_manager # save user_id
enum :house_tax_payer, PAYERS
enum :land_tax_payer, PAYERS
enum :bid_result, BID_RESULTS
field :details, localize: true
# Other fields
field :vendor # save user_id
field :contract_start_date, type: Date
field :contract_end_date, type: Date
field :construction_start_date, type: Date
field :construction_end_date, type: Date
field :operation_start_date, type: Date
field :operation_end_date, type: Date
field :free_period_start_date, type: Date
field :free_period_end_date, type: Date
field :renewal_permission, type: Boolean
field :sign_date, type: Date
field :handover_date, type: Date
field :deposit_payment_date, type: Date
field :deposit_type, type: String
field :deposit_exp_date, type: Date
field :insurance_type, type: String
field :insurance_payment_deadline, type: Date
field :insurance_payment_date, type: Date
field :other_commitment, localize: true
field :note, localize: true
belongs_to :venue_management_main
belongs_to :venue_management_inviting
has_many :venue_management_links, :as => :venue_object, :autosave => true, :dependent => :destroy
accepts_nested_attributes_for :venue_management_links, :allow_destroy => true
end

View File

@ -13,10 +13,10 @@ class VenueManagementInviting
field :case_no, type: String
field :publish_times, type: Integer
field :start_date, type: Date, default: Time.now
field :end_date, type: Date, default: Time.now
field :close_date, type: Date, default: Time.now
field :bid_date, type: Date, default: Time.now
field :evaluation_date, type: Date, default: Time.now
field :end_date, type: Date
field :close_date, type: Date
field :bid_date, type: Date
field :evaluation_date, type: Date
field :early_rent, type: Integer
field :operation_rent, type: Integer
field :royalty, type: Integer

View File

@ -38,6 +38,7 @@ class VenueManagementMain
has_many :venue_management_links, :autosave => true, :dependent => :destroy
has_many :venue_management_invitings, :autosave => true, :dependent => :destroy
has_many :venue_management_memorabilias, :autosave => true, :dependent => :destroy
has_many :venue_management_contracts, :autosave => true, :dependent => :destroy
has_many :venue_management_files, :autosave => true, :dependent => :destroy
has_many :venue_management_item_contents, :autosave => true, :dependent => :destroy
has_many :venue_management_signups, :autosave => true, :dependent => :destroy

View File

@ -0,0 +1,204 @@
<% content_for :page_specific_css do %>
<%= stylesheet_link_tag "lib/main-forms" %>
<%= stylesheet_link_tag "lib/fileupload" %>
<%= stylesheet_link_tag "lib/main-list" %>
<% end %>
<% content_for :page_specific_javascript do %>
<%= javascript_include_tag "lib/bootstrap-fileupload" %>
<%= javascript_include_tag "lib/bootstrap-datetimepicker" %>
<%= javascript_include_tag "lib/datetimepicker/datetimepicker.js" %>
<%= javascript_include_tag "lib/file-type" %>
<%= javascript_include_tag "lib/module-area" %>
<% end %>
<!-- Input Area -->
<div class="input-area">
<!-- Module -->
<div class="tab-content module-area">
<!-- Basic Module -->
<div class="tab-pane fade in active" id="basic">
<%= f.hidden_field :venue_management_main_id %>
<div class="control-group">
<label class="control-label muted"><%= t('vm_contract.case_no') %></label>
<div class="controls">
<%= f.select :venue_management_inviting_id, @venue_management.venue_management_invitings.map { |i| [ i.case_no, i.id ] }, :include_blank => true %>
</div>
</div>
<div class="control-group">
<label class="control-label muted"><%= t('vm_contract.contract_start_date') %></label>
<div class="controls">
<%= f.datetime_picker :contract_start_date, :no_label => true, :format=>"yyyy/MM/dd", :new_record => @venue_management_contract.new_record? %>
</div>
</div>
<div class="control-group">
<label class="control-label muted"><%= t('vm_contract.contract_end_date') %></label>
<div class="controls">
<%= f.datetime_picker :contract_end_date, :no_label => true, :format=>"yyyy/MM/dd", :new_record => @venue_management_contract.new_record? %>
</div>
</div>
<div class="control-group">
<label class="control-label muted"><%= t('vm_contract.construction_start_date') %></label>
<div class="controls">
<%= f.datetime_picker :construction_start_date, :no_label => true, :format=>"yyyy/MM/dd", :new_record => @venue_management_contract.new_record? %>
</div>
</div>
<div class="control-group">
<label class="control-label muted"><%= t('vm_contract.construction_end_date') %></label>
<div class="controls">
<%= f.datetime_picker :construction_end_date, :no_label => true, :format=>"yyyy/MM/dd", :new_record => @venue_management_contract.new_record? %>
</div>
</div>
<div class="control-group">
<label class="control-label muted"><%= t('vm_contract.operation_start_date') %></label>
<div class="controls">
<%= f.datetime_picker :operation_start_date, :no_label => true, :format=>"yyyy/MM/dd", :new_record => @venue_management_contract.new_record? %>
</div>
</div>
<div class="control-group">
<label class="control-label muted"><%= t('vm_contract.operation_end_date') %></label>
<div class="controls">
<%= f.datetime_picker :operation_end_date, :no_label => true, :format=>"yyyy/MM/dd", :new_record => @venue_management_contract.new_record? %>
</div>
</div>
<div class="control-group">
<label class="control-label muted"><%= t('vm_contract.free_period_start_date') %></label>
<div class="controls">
<%= f.datetime_picker :free_period_start_date, :no_label => true, :format=>"yyyy/MM/dd", :new_record => @venue_management_contract.new_record? %>
</div>
</div>
<div class="control-group">
<label class="control-label muted"><%= t('vm_contract.free_period_end_date') %></label>
<div class="controls">
<%= f.datetime_picker :free_period_end_date, :no_label => true, :format=>"yyyy/MM/dd", :new_record => @venue_management_contract.new_record? %>
</div>
</div>
<div class="control-group">
<label class="control-label muted"><%= t('vm_contract.sign_date') %></label>
<div class="controls">
<%= f.datetime_picker :sign_date, :no_label => true, :format=>"yyyy/MM/dd", :new_record => @venue_management_contract.new_record? %>
</div>
</div>
<div class="control-group">
<label class="control-label muted"><%= t('vm_contract.handover_date') %></label>
<div class="controls">
<%= f.datetime_picker :handover_date, :no_label => true, :format=>"yyyy/MM/dd", :new_record => @venue_management_contract.new_record? %>
</div>
</div>
<div class="control-group">
<label class="control-label muted"><%= t('vm_contract.deposit_payment_date') %></label>
<div class="controls">
<%= f.datetime_picker :deposit_payment_date, :no_label => true, :format=>"yyyy/MM/dd", :new_record => @venue_management_contract.new_record? %>
</div>
</div>
<div class="control-group">
<label class="control-label muted"><%= t('vm_contract.deposit_type') %></label>
<div class="controls">
<%= f.text_field :deposit_type %>
</div>
</div>
<div class="control-group">
<label class="control-label muted"><%= t('vm_contract.deposit_exp_date') %></label>
<div class="controls">
<%= f.datetime_picker :deposit_exp_date, :no_label => true, :format=>"yyyy/MM/dd", :new_record => @venue_management_contract.new_record? %>
</div>
</div>
<div class="control-group">
<label class="control-label muted"><%= t('vm_contract.insurance_type') %></label>
<div class="controls">
<%= f.text_field :insurance_type %>
</div>
</div>
<div class="control-group">
<label class="control-label muted"><%= t('vm_contract.insurance_payment_deadline') %></label>
<div class="controls">
<%= f.datetime_picker :insurance_payment_deadline, :no_label => true, :format=>"yyyy/MM/dd", :new_record => @venue_management_contract.new_record? %>
</div>
</div>
<div class="control-group">
<label class="control-label muted"><%= t('vm_contract.insurance_payment_date') %></label>
<div class="controls">
<%= f.datetime_picker :insurance_payment_date, :no_label => true, :format=>"yyyy/MM/dd", :new_record => @venue_management_contract.new_record? %>
</div>
</div>
</div>
</div>
<!-- Language Tabs -->
<div class="nav-name"><strong><%= t(:language) %></strong></div>
<ul class="nav nav-pills language-nav">
<% @site_in_use_locales.each_with_index do |locale, i| %>
<li class="<%= 'active' if i == 0 %>">
<a data-toggle="tab" href=".<%= locale %>"><%= t(locale) %></a>
</li>
<% end %>
</ul>
<!-- Language -->
<div class="tab-content language-area">
<% @site_in_use_locales.each_with_index do |locale, i| %>
<div class="<%= locale %> tab-pane fade <%= ( i == 0 ) ? "in active" : '' %>">
<!-- Content -->
<div class="control-group input-content">
<label class="control-label muted"><%= t('vm_contract.other_commitment') %></label>
<div class="controls">
<div class="textarea">
<%= f.fields_for :other_commitment_translations do |f| %>
<%= f.cktext_area locale, rows: 5, class: "input-block-level", :value => (@venue_management_contract.details_translations[locale] rescue nil) %>
<% end %>
</div>
</div>
</div>
<div class="control-group input-content">
<label class="control-label muted"><%= t('vm_contract.note') %></label>
<div class="controls">
<div class="textarea">
<%= f.fields_for :note_translations do |f| %>
<%= f.cktext_area locale, rows: 5, class: "input-block-level", :value => (@venue_management_contract.details_translations[locale] rescue nil) %>
<% end %>
</div>
</div>
</div>
</div>
<% end %>
<!-- Link -->
<div class="control-group">
<label class="control-label muted"><%= t(:link) %></label>
<div class="controls add-input">
<!-- Exist -->
<% if @venue_management_contract && !@venue_management_contract.venue_management_links.blank? %>
<div class="exist">
<% @venue_management_contract.venue_management_links.each_with_index do |venue_management_link, i| %>
<%= f.fields_for :venue_management_links, venue_management_link do |f| %>
<%= render :partial => 'form_link', :object => venue_management_link, :locals => {:f => f, :i => i} %>
<% end %>
<% end %>
<hr>
</div>
<% end %>
<!-- Add -->
<div class="add-target">
</div>
<p class="add-btn">
<%= hidden_field_tag 'venue_management_link_field_count', @venue_management_contract.venue_management_links.count %>
<a id="add_link" class="trigger btn btn-small btn-primary"><i class="icons-plus"></i> <%= t(:add) %></a>
</p>
</div>
</div>
</div>
</div>
<!-- Form Actions -->
<div class="form-actions">
<%= get_referer_url[:venue_managemention] rescue "" %>
<%= f.submit t('submit'), class: 'btn btn-primary' %>
<input type="hidden" name="referer_url" value="<%= get_referer_url %>">
<%= link_to t('cancel'), venue_management_contracts_admin_venue_management_path(id: @venue_management.id), :class=>"btn" %>
</div>

View File

@ -0,0 +1,55 @@
<script>
if(document.querySelectorAll("#orbit-bar").length==0) location.reload();
</script>
<% if 'venue_management_contracts' == params[:action] %>
<h4><%= @venue_management.title %></h4>
<% end %>
<table class="table main-list">
<thead>
<tr class="sort-header">
<% @table_fields.each do |f| %>
<%= thead(f) %>
<% end %>
</tr>
</thead>
<tbody>
<% @contracts.each do |contract| %>
<tr>
<% if 'venue_management_contracts' != params[:action] %>
<td><%= contract.venue_management_main.title %></td>
<% end %>
<td>
<%= link_to contract.case_no, admin_venue_management_contract_path(contract.id), :target => '_blank' %>
<div class="quick-edit">
<ul class="nav nav-pills">
<% if can_edit_or_delete?(contract) %>
<li><%= link_to t(:edit), edit_admin_venue_management_contract_path(contract.id) %></li>
<li><a href="#" class="delete text-error" rel="/admin/venue_management_contracts/<%=contract.id.to_s%>"><%= t(:delete_) %></a></li>
<% end %>
</ul>
</div>
</td>
<td><%= contract.vendor %></td>
<td><%= "#{contract.contract_start_date} / #{contract.contract_end_date}" %></td>
<td><%= t("vm_contract.renewal.#{contract.renewal_permission}") if contract.renewal_permission.present? %></td>
<td><%= contract.note %></td>
</tr>
<% end %>
</tbody>
</table>
<%=
content_tag :div, class: "bottomnav clearfix" do
content_tag :div, paginate(@contracts), class: "pagination pagination-centered"
end
%>
<% if @venue_management.present? %>
<!-- footer -->
<div class="bottomnav clearfix">
<div class="action pull-right">
<%= link_to content_tag(:i, nil, class: "icons-plus") + " " + t(:add), new_admin_venue_management_contract_path(id: @venue_management.id), class: "btn btn-primary" %>
</div>
</div>
<!-- footer:end -->
<% end %>

View File

@ -0,0 +1,5 @@
<%= form_for @venue_management_contract, url: admin_venue_management_contract_path(@venue_management_contract), html: {class: "form-horizontal main-forms"} do |f| %>
<fieldset>
<%= render :partial => 'form', locals: {f: f} %>
</fieldset>
<% end %>

View File

@ -0,0 +1,4 @@
<span id="index_table">
<%= render 'index' %>
</span>
<%= render 'layouts/delete_modal', delete_options: @delete_options %>

View File

@ -0,0 +1,5 @@
<%= form_for @venue_management_contract, url: admin_venue_management_contracts_path, html: {class: "form-horizontal main-forms"} do |f| %>
<fieldset>
<%= render :partial => 'form', locals: {f: f} %>
</fieldset>
<% end %>

View File

@ -34,7 +34,9 @@
</td>
<td><%= VenueManagementMain.time_range(venue_management.venue_management_start_date, venue_management.venue_management_end_date) %></td>
<td><%= VenueManagementMain.time_range(venue_management.signup_start_date, venue_management.signup_end_date) %></td>
<td><a href="/admin/venue_managements/<%=venue_management.id.to_s%>/venue_management_signup"><%= venue_management.venue_management_signups.count %></a></td>
<td>
<%= link_to venue_management.venue_management_contracts.count, venue_management_contracts_admin_venue_management_path(venue_management.id) %>
</td>
<td>
<%= link_to venue_management.venue_management_invitings.count, venue_management_invitings_admin_venue_management_path(venue_management.id) %>
</td>

View File

@ -0,0 +1,5 @@
<span id="index_table">
<%= render 'admin/venue_management_contracts/index' %>
</span>
<%= render 'layouts/delete_modal', delete_options: @delete_options %>

View File

@ -78,8 +78,9 @@ en:
event_during: Current contract period #活動期間
contribute_during: Contribute During #投稿期間
signup_during: Inviting contractor period #報名期間
signup_count: Contract history #報名人數
inviting_hostory: Inviting history
signup_count: Inviting contractor count
contract_history: Contract history
inviting_history: Inviting history
memorabilia: Memorabilia
signup: Inviting Contractor
export: Export #匯出
@ -87,6 +88,9 @@ en:
set_venue_management_submission_field: Set Submission Field
set_venue_management_signup_field: Set Sign Up Field #圈選設定
set_venue_management_item_content: Set Item Content #項目設定
set_venue_management_contracts: Contract History
set_venue_management_invitings: Inviting History
set_venue_management_memorabilias: Memorabilia
set_venue_management_agreements: Personal Data Usage Agreements #個資宣告設定
venue_management_agreements_content: Content of Personal Data Usage Agreements #個資宣告內容
to_require: Should Be Filled? #是否必填
@ -165,3 +169,29 @@ en:
case_no: 'Case No.'
event_date: Event Date
details: Details
vm_contract:
case_no: 'Case No.'
vendor: Vendor
start_end: Contract Duration
contract_start_date: Contract Start
contract_end_date: Contract End
construction_start_date: Construction Start
construction_end_date: Construction End
operation_start_date: Operation Start
operation_end_date: Operation End
free_period_start_date: Free Period Start
free_period_end_date: Free Period End
renewal_permission: Renewal Permission
renewal:
'true': 'Yes'
'false': 'No'
sign_date: Sign Date
handover_date: Handover Date
deposit_payment_date: Deposit Payment Date
deposit_type: Deposit Type
deposit_exp_date: Deposit EXP Date
insurance_type: Insurance Type
insurance_payment_deadline: Insurance Payment Deadline
insurance_payment_date: Insurance Payment Date
other_commitment: Other Commitments
note: Note

View File

@ -78,8 +78,9 @@ zh_tw:
event_during: 合約期間
contribute_during: 投稿期間
signup_during: 招商期間
signup_count: 履約紀錄
inviting_hostory: 招商公告
signup_count: 招商次數
contract_history: 履約紀錄
inviting_history: 招商公告
memorabilia: 大事記
signup: 招商
export: 匯出
@ -87,10 +88,10 @@ zh_tw:
set_venue_management_submission_field: 上傳介面欄位設定
set_venue_management_signup_field: 圈選設定
set_venue_management_item_content: 項目設定
set_venue_management_agreements: 個資宣告設定
set_venue_management_contracts: 履約記錄
set_venue_management_invitings: 招商公告
set_venue_management_memorabilias: 大事記
set_venue_management_agreements: 個資宣告設定
venue_management_agreements_content: 個資宣告內容
to_require: 是否必填
sign_up_not_yet: 報名時間未開始
@ -168,3 +169,29 @@ zh_tw:
case_no: 相關案號
event_date: 事件日期
details: 事件內容
vm_contract:
case_no: 案號
vendor: 廠商
start_end: 契約期間
contract_start_date: 契約期間開始
contract_end_date: 契約期間結束
construction_start_date: 興建期間開始
construction_end_date: 興建期間結束
operation_start_date: 營運期間開始
operation_end_date: 營運期間結束
free_period_start_date: 免費期間開始
free_period_end_date: 免費期間結束
renewal_permission: 是否得續約
renewal:
'true':
'false':
sign_date: 簽約日期
handover_date: 點交日期
deposit_payment_date: 履約保證金繳交日期
deposit_type: 履約保證金繳交形式
deposit_exp_date: 履約保證金效期
insurance_type: 保險種類
insurance_payment_deadline: 保險繳交期限
insurance_payment_date: 保險繳交日期
other_commitment: 其他回饋或承諾事項
note: 備註

View File

@ -14,6 +14,7 @@ Rails.application.routes.draw do
get 'venue_management_submission_field'
get 'venue_management_invitings'
get 'venue_management_memorabilias'
get 'venue_management_contracts'
end
end
resources :venue_management_items do
@ -26,6 +27,7 @@ Rails.application.routes.draw do
resources :venue_management_item_contents
resources :venue_management_invitings
resources :venue_management_memorabilias
resources :venue_management_contracts
end
resources :venue_managements do

View File

@ -52,6 +52,11 @@ module VenueManagement
:priority => 3,
:active_for_action => { 'admin/venue_managements' => 'venue_management_memorabilias' },
:available_for => 'managers'
context_link 'venue_management.set_venue_management_contracts',
:link_path => 'admin_venue_management_contracts_path',
:priority => 3,
:active_for_action => { 'admin/venue_managements' => 'venue_management_contracts' },
:available_for => 'managers'
end
end
end