# frozen_string_literal: true require 'orbit_form_helper' class VenueManagementInviting include Mongoid::Document include Mongoid::Timestamps require 'mongoid/enum' include Mongoid::Enum include OrbitTag::Taggable PAYERS = [ :school, :vendor].freeze BID_RESULTS = [ :empty ,:failure, :abandoned, :qualified].freeze 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: DateTime field :bid_date, type: DateTime field :evaluation_date, type: DateTime 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 has_many :venue_management_contracts has_many :venue_management_memorabilias, :class_name => 'VenueManagementMemorabilia', :foreign_key => "venue_management_memorabilia_ids" belongs_to :venue_management_main include VenueLinkFile after_create do venue_management = self.venue_management_main if venue_management venue_management.inviting_history = venue_management.inviting_history + 1 venue_management.save(:validate=>false) end end after_destroy do venue_management = self.venue_management_main if venue_management venue_management.inviting_history = venue_management.inviting_history - 1 venue_management.save(:validate=>false) end end def display_royalty self.royalty.to_s.gsub("\r\n","
").html_safe end def display_close_date self.close_date.strftime("%Y/%m/%d %H:%M") rescue "" end def display_bid_date self.bid_date.strftime("%Y/%m/%d %H:%M") rescue "" end def display_evaluation_date self.evaluation_date.strftime("%Y/%m/%d %H:%M") rescue "" end def display_case_no return (self.case_no.blank? ? I18n.t(:empty) : self.case_no) end def display_details html = self.details.to_s.split("\r\n").select{|s| !s.blank?}.first return Nokogiri::HTML(html).css("body").text end before_save do contracts = self.venue_management_contracts org_inviting = VenueManagementInviting.find(self.id) rescue nil contracts.each do |contract| contract.update_inviting(self,org_inviting,contract) end end end