# frozen_string_literal: true require 'orbit_form_helper' class VenueManagementContract include Mongoid::Document include Mongoid::Timestamps require 'mongoid/enum' include Mongoid::Enum PAYERS = [ :school, :vendor].freeze BID_RESULTS = [ :empty , :failure, :abandoned, :qualified].freeze # Copy from Inviting field :renewal_permission, type: Boolean,default: false field :renewal_deadline, type: Date field :case_no, type: String field :contractor_ids, type: Array,default: [] 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: String 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_amount, type: String 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 :insurance_type2, type: String field :insurance_payment_deadline2, type: Date field :insurance_payment_date2, type: Date field :insurance_type3, type: String field :insurance_payment_deadline3, type: Date field :insurance_payment_date3, type: Date field :other_commitment, localize: true field :note, localize: true belongs_to :venue_management_main belongs_to :venue_management_inviting include VenueLinkFile def deposit_amount_type_exp_date return "#{self.deposit_amount}/#{self.deposit_type}/#{self.deposit_exp_date}" end def display_note html = self.note.to_s.split("\r\n").select{|s| !s.blank?}.first return Nokogiri::HTML(html).css("body").text end def display_other_commitment html = self.other_commitment.to_s.split("\r\n").select{|s| !s.blank?}.first return Nokogiri::HTML(html).css("body").text end def display_royalty self.royalty.to_s.gsub("\r\n","
").html_safe end 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 end else self[:case_no] = nil end 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_] != (check_inviting.send(attr_) rescue nil) update_flag = false end end end if update_flag && !inviting.nil? %i(early_rent operation_rent royalty house_tax_payer land_tax_payer).each do |attr_| self[attr_] = (inviting.send(attr_) rescue nil) end end if save_flag self.save end end def contractors return( MemberProfile.where(:id.in=>self.contractor_ids).to_a rescue []) end def display_contractors return self.contractors.map{|m| m.name}.join(" , ") end def display_tags self.venue_management_inviting.tags.map{|t| t.name}.join(" , ") rescue "" end def display_case_no return (self.case_no.blank? ? I18n.t(:empty) : self.case_no) 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