From 5ea12df38d180ebcc875e977d62b313e2ecee9cf Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Fri, 31 Jul 2020 01:30:14 +0800 Subject: [PATCH] Add Contract Model & CRUD --- .../venue_management_contracts_controller.rb | 73 +++++++ .../admin/venue_managements_controller.rb | 23 +- app/models/venue_management_contract.rb | 58 +++++ app/models/venue_management_inviting.rb | 8 +- app/models/venue_management_main.rb | 1 + .../venue_management_contracts/_form.html.erb | 204 ++++++++++++++++++ .../_index.html.erb | 55 +++++ .../venue_management_contracts/edit.html.erb | 5 + .../venue_management_contracts/index.html.erb | 4 + .../venue_management_contracts/new.html.erb | 5 + .../admin/venue_managements/_index.html.erb | 4 +- .../venue_management_contracts.html.erb | 5 + config/locales/en.yml | 34 ++- config/locales/zh_tw.yml | 33 ++- config/routes.rb | 2 + lib/venue_management/engine.rb | 5 + 16 files changed, 507 insertions(+), 12 deletions(-) create mode 100644 app/controllers/admin/venue_management_contracts_controller.rb create mode 100644 app/models/venue_management_contract.rb create mode 100644 app/views/admin/venue_management_contracts/_form.html.erb create mode 100644 app/views/admin/venue_management_contracts/_index.html.erb create mode 100644 app/views/admin/venue_management_contracts/edit.html.erb create mode 100644 app/views/admin/venue_management_contracts/index.html.erb create mode 100644 app/views/admin/venue_management_contracts/new.html.erb create mode 100644 app/views/admin/venue_managements/venue_management_contracts.html.erb diff --git a/app/controllers/admin/venue_management_contracts_controller.rb b/app/controllers/admin/venue_management_contracts_controller.rb new file mode 100644 index 0000000..8a57e0d --- /dev/null +++ b/app/controllers/admin/venue_management_contracts_controller.rb @@ -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 diff --git a/app/controllers/admin/venue_managements_controller.rb b/app/controllers/admin/venue_managements_controller.rb index 226054a..081596a 100644 --- a/app/controllers/admin/venue_managements_controller.rb +++ b/app/controllers/admin/venue_managements_controller.rb @@ -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 diff --git a/app/models/venue_management_contract.rb b/app/models/venue_management_contract.rb new file mode 100644 index 0000000..3613f6e --- /dev/null +++ b/app/models/venue_management_contract.rb @@ -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 diff --git a/app/models/venue_management_inviting.rb b/app/models/venue_management_inviting.rb index 1b40638..58336ef 100644 --- a/app/models/venue_management_inviting.rb +++ b/app/models/venue_management_inviting.rb @@ -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 diff --git a/app/models/venue_management_main.rb b/app/models/venue_management_main.rb index 628f7cd..4537bbc 100644 --- a/app/models/venue_management_main.rb +++ b/app/models/venue_management_main.rb @@ -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 diff --git a/app/views/admin/venue_management_contracts/_form.html.erb b/app/views/admin/venue_management_contracts/_form.html.erb new file mode 100644 index 0000000..145fc63 --- /dev/null +++ b/app/views/admin/venue_management_contracts/_form.html.erb @@ -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 %> + +
+ + +
+ +
+ <%= f.hidden_field :venue_management_main_id %> +
+ +
+ <%= f.select :venue_management_inviting_id, @venue_management.venue_management_invitings.map { |i| [ i.case_no, i.id ] }, :include_blank => true %> +
+
+
+ +
+ <%= f.datetime_picker :contract_start_date, :no_label => true, :format=>"yyyy/MM/dd", :new_record => @venue_management_contract.new_record? %> +
+
+
+ +
+ <%= f.datetime_picker :contract_end_date, :no_label => true, :format=>"yyyy/MM/dd", :new_record => @venue_management_contract.new_record? %> +
+
+
+ +
+ <%= f.datetime_picker :construction_start_date, :no_label => true, :format=>"yyyy/MM/dd", :new_record => @venue_management_contract.new_record? %> +
+
+
+ +
+ <%= f.datetime_picker :construction_end_date, :no_label => true, :format=>"yyyy/MM/dd", :new_record => @venue_management_contract.new_record? %> +
+
+
+ +
+ <%= f.datetime_picker :operation_start_date, :no_label => true, :format=>"yyyy/MM/dd", :new_record => @venue_management_contract.new_record? %> +
+
+
+ +
+ <%= f.datetime_picker :operation_end_date, :no_label => true, :format=>"yyyy/MM/dd", :new_record => @venue_management_contract.new_record? %> +
+
+
+ +
+ <%= f.datetime_picker :free_period_start_date, :no_label => true, :format=>"yyyy/MM/dd", :new_record => @venue_management_contract.new_record? %> +
+
+
+ +
+ <%= f.datetime_picker :free_period_end_date, :no_label => true, :format=>"yyyy/MM/dd", :new_record => @venue_management_contract.new_record? %> +
+
+
+ +
+ <%= f.datetime_picker :sign_date, :no_label => true, :format=>"yyyy/MM/dd", :new_record => @venue_management_contract.new_record? %> +
+
+
+ +
+ <%= f.datetime_picker :handover_date, :no_label => true, :format=>"yyyy/MM/dd", :new_record => @venue_management_contract.new_record? %> +
+
+
+ +
+ <%= f.datetime_picker :deposit_payment_date, :no_label => true, :format=>"yyyy/MM/dd", :new_record => @venue_management_contract.new_record? %> +
+
+
+ +
+ <%= f.text_field :deposit_type %> +
+
+
+ +
+ <%= f.datetime_picker :deposit_exp_date, :no_label => true, :format=>"yyyy/MM/dd", :new_record => @venue_management_contract.new_record? %> +
+
+
+ +
+ <%= f.text_field :insurance_type %> +
+
+
+ +
+ <%= f.datetime_picker :insurance_payment_deadline, :no_label => true, :format=>"yyyy/MM/dd", :new_record => @venue_management_contract.new_record? %> +
+
+
+ +
+ <%= f.datetime_picker :insurance_payment_date, :no_label => true, :format=>"yyyy/MM/dd", :new_record => @venue_management_contract.new_record? %> +
+
+
+
+ + + + + + +
+ + <% @site_in_use_locales.each_with_index do |locale, i| %> + +
"> + + +
+ +
+
+ <%= 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 %> +
+
+
+ +
+ +
+
+ <%= 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 %> +
+
+
+
+ + <% end %> + + +
+ +
+ + + <% if @venue_management_contract && !@venue_management_contract.venue_management_links.blank? %> +
+ <% @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 %> +
+
+ <% end %> + + +
+
+

+ <%= hidden_field_tag 'venue_management_link_field_count', @venue_management_contract.venue_management_links.count %> + <%= t(:add) %> +

+
+
+
+
+ + +
+ <%= get_referer_url[:venue_managemention] rescue "" %> + <%= f.submit t('submit'), class: 'btn btn-primary' %> + + <%= link_to t('cancel'), venue_management_contracts_admin_venue_management_path(id: @venue_management.id), :class=>"btn" %> +
diff --git a/app/views/admin/venue_management_contracts/_index.html.erb b/app/views/admin/venue_management_contracts/_index.html.erb new file mode 100644 index 0000000..8af69d2 --- /dev/null +++ b/app/views/admin/venue_management_contracts/_index.html.erb @@ -0,0 +1,55 @@ + +<% if 'venue_management_contracts' == params[:action] %> +

<%= @venue_management.title %>

+<% end %> + + + + <% @table_fields.each do |f| %> + <%= thead(f) %> + <% end %> + + + + <% @contracts.each do |contract| %> + + <% if 'venue_management_contracts' != params[:action] %> + + <% end %> + + + + + + + <% end %> + +
<%= contract.venue_management_main.title %> + <%= link_to contract.case_no, admin_venue_management_contract_path(contract.id), :target => '_blank' %> + +
+ +
+
<%= contract.vendor %><%= "#{contract.contract_start_date} / #{contract.contract_end_date}" %><%= t("vm_contract.renewal.#{contract.renewal_permission}") if contract.renewal_permission.present? %><%= contract.note %>
+ +<%= + content_tag :div, class: "bottomnav clearfix" do + content_tag :div, paginate(@contracts), class: "pagination pagination-centered" + end +%> +<% if @venue_management.present? %> + +
+
+ <%= 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" %> +
+
+ +<% end %> diff --git a/app/views/admin/venue_management_contracts/edit.html.erb b/app/views/admin/venue_management_contracts/edit.html.erb new file mode 100644 index 0000000..76a45dc --- /dev/null +++ b/app/views/admin/venue_management_contracts/edit.html.erb @@ -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| %> +
+ <%= render :partial => 'form', locals: {f: f} %> +
+<% end %> diff --git a/app/views/admin/venue_management_contracts/index.html.erb b/app/views/admin/venue_management_contracts/index.html.erb new file mode 100644 index 0000000..be82942 --- /dev/null +++ b/app/views/admin/venue_management_contracts/index.html.erb @@ -0,0 +1,4 @@ + + <%= render 'index' %> + +<%= render 'layouts/delete_modal', delete_options: @delete_options %> diff --git a/app/views/admin/venue_management_contracts/new.html.erb b/app/views/admin/venue_management_contracts/new.html.erb new file mode 100644 index 0000000..91b25b7 --- /dev/null +++ b/app/views/admin/venue_management_contracts/new.html.erb @@ -0,0 +1,5 @@ +<%= form_for @venue_management_contract, url: admin_venue_management_contracts_path, html: {class: "form-horizontal main-forms"} do |f| %> +
+ <%= render :partial => 'form', locals: {f: f} %> +
+<% end %> diff --git a/app/views/admin/venue_managements/_index.html.erb b/app/views/admin/venue_managements/_index.html.erb index 90dacf4..6f7cd7b 100644 --- a/app/views/admin/venue_managements/_index.html.erb +++ b/app/views/admin/venue_managements/_index.html.erb @@ -34,7 +34,9 @@ <%= VenueManagementMain.time_range(venue_management.venue_management_start_date, venue_management.venue_management_end_date) %> <%= VenueManagementMain.time_range(venue_management.signup_start_date, venue_management.signup_end_date) %> - <%= venue_management.venue_management_signups.count %> + + <%= link_to venue_management.venue_management_contracts.count, venue_management_contracts_admin_venue_management_path(venue_management.id) %> + <%= link_to venue_management.venue_management_invitings.count, venue_management_invitings_admin_venue_management_path(venue_management.id) %> diff --git a/app/views/admin/venue_managements/venue_management_contracts.html.erb b/app/views/admin/venue_managements/venue_management_contracts.html.erb new file mode 100644 index 0000000..127a2ac --- /dev/null +++ b/app/views/admin/venue_managements/venue_management_contracts.html.erb @@ -0,0 +1,5 @@ + + <%= render 'admin/venue_management_contracts/index' %> + + +<%= render 'layouts/delete_modal', delete_options: @delete_options %> diff --git a/config/locales/en.yml b/config/locales/en.yml index c84e375..e3f549b 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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 diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index be57a26..ba1ce1f 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -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: 備註 diff --git a/config/routes.rb b/config/routes.rb index ce2499c..3684580 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/lib/venue_management/engine.rb b/lib/venue_management/engine.rb index 3e88bfe..8c49d8e 100644 --- a/lib/venue_management/engine.rb +++ b/lib/venue_management/engine.rb @@ -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