Sha256: c0c3404bf452e33fbd819a6a668513efbdc90d8dde329f0eb5db9cce14af0694

Contents?: true

Size: 1.92 KB

Versions: 7

Compression:

Stored size: 1.92 KB

Contents

module EducodeSales
  class BusinessDeliverSubject < ApplicationRecord
    belongs_to :business
    has_many :business_subjects, dependent: :destroy
    has_many :subjects ,through: :business_subjects
    has_many :manages, as: :container, dependent: :destroy, class_name: "EducodeSales::BusinessSubjectStaff"


    # constructed:待建设, signed: 已签协议,construction: 建设中,completed: 已完成,delivered: 已交付, accepted: 已验收
    enum status: { constructed:1, signed:2, construction: 3, completed:4, delivered: 5, accepted: 6 }

    scope :undelivered, -> {where.not(status: "delivered")}
    # 实践课程完成统计
    def subject_competed_count
      all_count = subjects.count
      completed_count = subjects.where("subjects.status = 2 or subjects.public = 2").count

      " #{completed_count} / #{all_count} "
    end

    # 实训项目完成进度
    def shixun_competed_count
      " #{business_subjects.joins(:business_subject_shixuns).where("educode_sales_business_subject_shixuns.shixun_status in (6,7,8)").count } / #{business_subjects.joins(:business_subject_shixuns).count} "
    end

    # 课程经理
    def subject_manages
      manages.joins(staff: :user).pluck("CONCAT(users.lastname, users.firstname) ").join(",") || "--"
    end


    def delvier_date
      business.last_follow_up&.reception_at
    end

    def add_subjects(subject_ids = [])
      subjects = Subject.where.not(id: BusinessSubject.joins(:business_deliver_subject).pluck(:subject_id)).unhidden # 1先创建实践项目下,通过实践课程无法选该实践项目
      subject_ids.each do |item|
          now_subject = subjects.find_by(id: item)
          if now_subject.present?
            add_item = BusinessSubject.find_or_create_by(subject_id: item)
            add_item.update(business: business, business_deliver_subject_id: id)
          end
      end
    end

  end

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
educode_sales-1.10.74 app/models/educode_sales/business_deliver_subject.rb
educode_sales-1.10.73 app/models/educode_sales/business_deliver_subject.rb
educode_sales-1.10.72 app/models/educode_sales/business_deliver_subject.rb
educode_sales-1.10.71 app/models/educode_sales/business_deliver_subject.rb
educode_sales-1.10.70 app/models/educode_sales/business_deliver_subject.rb
educode_sales-1.10.59 app/models/educode_sales/business_deliver_subject.rb
educode_sales-1.10.58 app/models/educode_sales/business_deliver_subject.rb