educode_sales 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/educode_sales/businesses_controller.rb +4 -1
- data/app/controllers/educode_sales/contracts_controller.rb +17 -1
- data/app/controllers/educode_sales/follow_ups_controller.rb +13 -12
- data/app/controllers/educode_sales/home_controller.rb +14 -0
- data/app/controllers/educode_sales/invoices_controller.rb +219 -0
- data/app/controllers/educode_sales/key_person_controller.rb +1 -1
- data/app/controllers/educode_sales/money_plan_records_controller.rb +116 -0
- data/app/controllers/educode_sales/money_plans_controller.rb +32 -28
- data/app/controllers/educode_sales/sale_trends_controller.rb +2 -2
- data/app/controllers/educode_sales/sales_details_controller.rb +1 -1
- data/app/controllers/educode_sales/teachers_controller.rb +7 -2
- data/app/models/educode_sales/business.rb +7 -0
- data/app/models/educode_sales/invoice.rb +5 -0
- data/app/models/educode_sales/invoice_apply.rb +12 -0
- data/app/models/educode_sales/invoice_detail.rb +10 -0
- data/app/models/educode_sales/key_person.rb +1 -1
- data/app/models/educode_sales/money_plan.rb +27 -0
- data/app/models/educode_sales/money_plan_claim.rb +7 -0
- data/app/models/educode_sales/money_plan_record.rb +7 -0
- data/app/models/educode_sales/staff.rb +2 -0
- data/app/views/educode_sales/businesses/edit_plan.html.erb +1 -1
- data/app/views/educode_sales/businesses/key_person.json.jbuilder +1 -1
- data/app/views/educode_sales/contracts/_list.html.erb +1 -1
- data/app/views/educode_sales/follow_ups/index.json.jbuilder +1 -1
- data/app/views/educode_sales/follow_ups/teachers.json.jbuilder +1 -1
- data/app/views/educode_sales/home/search_contracts.json.jbuilder +9 -0
- data/app/views/educode_sales/home/search_money_plans.json.jbuilder +9 -0
- data/app/views/educode_sales/invoices/_apply_records.html.erb +276 -0
- data/app/views/educode_sales/invoices/apply.html.erb +443 -0
- data/app/views/educode_sales/invoices/apply_records.js.erb +1 -0
- data/app/views/educode_sales/invoices/apply_records.json.jbuilder +20 -0
- data/app/views/educode_sales/invoices/details.json.jbuilder +17 -0
- data/app/views/educode_sales/invoices/list.json.jbuilder +14 -0
- data/app/views/educode_sales/invoices/new.html.erb +177 -0
- data/app/views/educode_sales/invoices/sales_details.html.erb +88 -0
- data/app/views/educode_sales/invoices/sales_details.json.jbuilder +14 -0
- data/app/views/educode_sales/money_plan_records/_index.html.erb +258 -0
- data/app/views/educode_sales/money_plan_records/add.html.erb +101 -0
- data/app/views/educode_sales/money_plan_records/confirm_plan.html.erb +167 -0
- data/app/views/educode_sales/money_plan_records/index.js.erb +1 -0
- data/app/views/educode_sales/money_plan_records/index.json.jbuilder +26 -0
- data/app/views/educode_sales/money_plans/_index.html.erb +245 -0
- data/app/views/educode_sales/money_plans/add.html.erb +147 -0
- data/app/views/educode_sales/money_plans/index.json.jbuilder +41 -8
- data/app/views/educode_sales/money_plans/list.html.erb +56 -0
- data/app/views/educode_sales/sales_details/edit.html.erb +6 -0
- data/app/views/educode_sales/teachers/add_keys.html.erb +2 -2
- data/app/views/layouts/educode_sales/application.html.erb +245 -236
- data/config/routes.rb +32 -1
- data/db/migrate/20230527150102_add_category_to_educode_sales_money_plans.rb +7 -0
- data/db/migrate/20230528115654_create_educode_sales_money_plan_records.rb +13 -0
- data/db/migrate/20230529022020_create_educode_sales_money_plan_claims.rb +12 -0
- data/db/migrate/20230531144834_create_educode_sales_invoice_applies.rb +25 -0
- data/db/migrate/20230601011835_create_educode_sales_invoices.rb +14 -0
- data/db/migrate/20230601011943_create_educode_sales_invoice_details.rb +20 -0
- data/lib/educode_sales/version.rb +1 -1
- metadata +35 -4
- data/app/views/educode_sales/money_plans/index.html.erb +0 -222
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b46afaa19173f871423665f95aafafb3443518ad51810efb33b76d6d00d4c162
|
4
|
+
data.tar.gz: 43aa8f04c71a2ab4d9dc0cdcbc75f2171ab3f27b30c3732d0ffaacf6d1cf4503
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e2eeb2350a2fe54a6f4e01cfc40369538ba69dea82e74a5f95543e188b313975f5a7021cdc7da84d27a83993bda4161fc184a07f53eed4ae9f608c8f89b8bbd3
|
7
|
+
data.tar.gz: 0604716ff8a63448d01c579f4321e3e7699429f35b9dfec7d0f5c291dec9aca57e4abb5b8ffc16d4b9f2a5931f3c01d63f1f0dcba5362459eb8cd1da444f1997
|
@@ -384,7 +384,7 @@ module EducodeSales
|
|
384
384
|
end
|
385
385
|
|
386
386
|
def daily_paper
|
387
|
-
@followups = EducodeSales::FollowUp.where(staff_id: @current_admin.id).where("
|
387
|
+
@followups = EducodeSales::FollowUp.where(staff_id: @current_admin.id).where("created_at > ?", Time.now.beginning_of_day).order("created_at")
|
388
388
|
ab = EducodeSales::Common.where(extras: [EducodeSales::Common::ATYPE, EducodeSales::Common::BTYPE]).pluck(:id)
|
389
389
|
business = EducodeSales::FollowUp.joins("
|
390
390
|
JOIN educode_sales_businesses ON educode_sales_businesses.id = educode_sales_follow_ups.business_id
|
@@ -484,6 +484,9 @@ module EducodeSales
|
|
484
484
|
params[:sourcable_id] = ""
|
485
485
|
end
|
486
486
|
end
|
487
|
+
if ['会议活动', '渠道代理', '客户'].include?(params[:source_way] ) && params[:sourcable_id].blank?
|
488
|
+
params[:sourcable_type] = ""
|
489
|
+
end
|
487
490
|
if params[:sourcable_type].blank?
|
488
491
|
params[:sourcable_id] = ""
|
489
492
|
end
|
@@ -364,8 +364,24 @@ module EducodeSales
|
|
364
364
|
end
|
365
365
|
follow_up.staff = @current_admin
|
366
366
|
|
367
|
+
last_follow_up.assign_follow_ups.each do |d|
|
368
|
+
follow_up.assign_follow_ups.build(staff_id: d.staff_id)
|
369
|
+
end
|
370
|
+
|
367
371
|
if follow_up.save!
|
368
|
-
last_follow_up.
|
372
|
+
if last_follow_up.present?
|
373
|
+
last_follow_up.key_person.each do |d|
|
374
|
+
key_person = d.dup
|
375
|
+
key_person.follow_up_id = follow_up.id
|
376
|
+
key_person.save
|
377
|
+
end
|
378
|
+
last_follow_up.money_plans.each do |d|
|
379
|
+
money = d.dup
|
380
|
+
money.staff = @current_admin
|
381
|
+
money.follow_up_id = follow_up.id
|
382
|
+
money.save
|
383
|
+
end
|
384
|
+
end
|
369
385
|
|
370
386
|
contract_lists = EducodeSales::ContractDateList.clazzs.invert
|
371
387
|
data.each_with_index do |s, i|
|
@@ -234,22 +234,23 @@ module EducodeSales
|
|
234
234
|
# 从教师列表里选择的用户
|
235
235
|
teacher = Teacher.find(names[1])
|
236
236
|
key_peprson = KeyPerson.new(teacher_params)
|
237
|
+
key_peprson.name = teacher.name
|
237
238
|
key_peprson.teacher = teacher
|
238
|
-
|
239
|
+
elsif names[0] == 'u'
|
239
240
|
# 从头歌平台选择的用户
|
240
241
|
user = User.find(names[1])
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
)
|
242
|
+
key_peprson = KeyPerson.new(teacher_params)
|
243
|
+
teacher = EducodeSales::Teacher.find_or_initialize_by(name: user.real_name, department_id: user.department_id, user_id: user.id)
|
244
|
+
|
245
|
+
teacher.staff = @current_admin
|
246
|
+
teacher.professional_title = params[:professional_title]
|
247
|
+
teacher.job = params[:job]
|
248
|
+
teacher.is_key = true
|
249
249
|
teacher.save
|
250
|
+
key_peprson.name = teacher.name
|
251
|
+
key_peprson.teacher_id = teacher.id
|
252
|
+
else
|
250
253
|
key_peprson = KeyPerson.new(teacher_params)
|
251
|
-
teacher_id = EducodeSales::Teacher.find_by(name: user.real_name, department_id: user.department_id).id
|
252
|
-
key_peprson.teacher_id = teacher_id
|
253
254
|
end
|
254
255
|
|
255
256
|
follow_up.key_person << key_peprson
|
@@ -318,7 +319,7 @@ module EducodeSales
|
|
318
319
|
end
|
319
320
|
|
320
321
|
def teacher_params
|
321
|
-
params.permit(:professional_title, :job, :attitude_id, :sex, :birth_date, :remark, :tel)
|
322
|
+
params.permit(:professional_title, :job, :attitude_id, :sex, :birth_date, :remark, :tel, :name)
|
322
323
|
end
|
323
324
|
end
|
324
325
|
end
|
@@ -77,6 +77,13 @@ module EducodeSales
|
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
80
|
+
def search_contracts
|
81
|
+
@data = Business
|
82
|
+
if params[:q].present?
|
83
|
+
@data = @data.where("name like :q ", q: "%#{params[:q]}%").limit(20)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
80
87
|
def staff_departments
|
81
88
|
@departments = Department.where(school_id: params[:school_id])
|
82
89
|
if params[:q].present?
|
@@ -111,5 +118,12 @@ module EducodeSales
|
|
111
118
|
end
|
112
119
|
end
|
113
120
|
|
121
|
+
def search_money_plans
|
122
|
+
@data = MoneyPlan.joins(business: :school)
|
123
|
+
if params[:q].present?
|
124
|
+
@data = @data.where("educode_sales_businesses.name like :q OR educode_sales_businesses.number like :q OR schools.name like :q ", q: "%#{params[:q]}%").limit(20)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
114
128
|
end
|
115
129
|
end
|
@@ -0,0 +1,219 @@
|
|
1
|
+
require_dependency "educode_sales/application_controller"
|
2
|
+
|
3
|
+
module EducodeSales
|
4
|
+
class InvoicesController < ApplicationController
|
5
|
+
|
6
|
+
def index
|
7
|
+
end
|
8
|
+
|
9
|
+
def apply
|
10
|
+
render layout: false
|
11
|
+
end
|
12
|
+
|
13
|
+
def create_apply
|
14
|
+
business = Business.find(params[:business_id])
|
15
|
+
count = EducodeSales::InvoiceApply.where("created_at > ?", Time.now.beginning_of_day).size + 1
|
16
|
+
invoice_apply = InvoiceApply.find_or_initialize_by(business_id: business.id) do |d|
|
17
|
+
d.number = Time.now.strftime("%y%m%d").gsub("-", "") + rand(10..99).to_s + ("%04d" % count)
|
18
|
+
d.state = '审核中'
|
19
|
+
end
|
20
|
+
invoice_apply.staff = @current_admin
|
21
|
+
invoice_apply.assign_attributes(apply_params)
|
22
|
+
ActiveRecord::Base.transaction do
|
23
|
+
invoice_apply.save!
|
24
|
+
params[:details].each do |d|
|
25
|
+
detail = invoice_apply.invoice_details.new({
|
26
|
+
sale_detail_id: d['id'],
|
27
|
+
specification: d['specification'],
|
28
|
+
business_id: business.id,
|
29
|
+
unit: d['unit'],
|
30
|
+
category: d['category'],
|
31
|
+
state: '待开票',
|
32
|
+
name: d['name'],
|
33
|
+
num: d['num'],
|
34
|
+
price: d['price'],
|
35
|
+
amount: d['amount']})
|
36
|
+
detail.save!
|
37
|
+
end
|
38
|
+
end
|
39
|
+
render_success
|
40
|
+
end
|
41
|
+
|
42
|
+
def details
|
43
|
+
business = Business.find(params[:id])
|
44
|
+
invoice_apply = business.invoice_apply
|
45
|
+
if invoice_apply
|
46
|
+
if params[:state].present?
|
47
|
+
@data = invoice_apply.invoice_details.where(state: params[:state])
|
48
|
+
else
|
49
|
+
@data = invoice_apply.invoice_details
|
50
|
+
end
|
51
|
+
else
|
52
|
+
@data = InvoiceDetail.none
|
53
|
+
end
|
54
|
+
@data = @data.page(params[:page]).per(params[:limit])
|
55
|
+
end
|
56
|
+
|
57
|
+
def sales_details
|
58
|
+
respond_to do |format|
|
59
|
+
format.html do
|
60
|
+
render layout: false
|
61
|
+
end
|
62
|
+
format.json do
|
63
|
+
business = Business.find(params[:id])
|
64
|
+
@data = business.sales_details.page(params[:page]).per(params[:limit])
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def invoice_amount
|
70
|
+
business = Business.find(params[:id])
|
71
|
+
render json: {
|
72
|
+
actual_amount: business&.last_follow_up&.actual_amount,
|
73
|
+
invoice_pass: business&.invoice_details&.sum(:amount),
|
74
|
+
invoice_category: business&.invoice_apply&.category || '',
|
75
|
+
is_tax_rebate: business&.invoice_apply&.is_tax_rebate.to_s,
|
76
|
+
ticket_at: business&.invoice_apply&.ticket_at || '',
|
77
|
+
name: business&.invoice_apply&.name || '',
|
78
|
+
taxpaper_number: business&.invoice_apply&.taxpaper_number || '',
|
79
|
+
address: business&.invoice_apply&.address || '',
|
80
|
+
phone: business&.invoice_apply&.phone || '',
|
81
|
+
bank: business&.invoice_apply&.bank || '',
|
82
|
+
bank_number: business&.invoice_apply&.bank_number || '',
|
83
|
+
}
|
84
|
+
end
|
85
|
+
|
86
|
+
|
87
|
+
def apply_records
|
88
|
+
respond_to do |format|
|
89
|
+
format.html do
|
90
|
+
end
|
91
|
+
format.js do
|
92
|
+
@staffs = Staff.joins(:invoice_applys).includes(:user).distinct.map { |d| [d.user.real_name, d.id]}
|
93
|
+
end
|
94
|
+
format.json do
|
95
|
+
@data = InvoiceApply
|
96
|
+
|
97
|
+
unless @current_admin.is_admin?
|
98
|
+
@data = @data.left_joins(business: [last_follow_up: :assign_follow_ups]).where("educode_sales_assign_follow_ups.staff_id = :staff OR educode_sales_invoice_applies.staff_id = :staff", staff: @current_admin.id)
|
99
|
+
end
|
100
|
+
|
101
|
+
if params[:q].present? && params[:q][:payer_name].present?
|
102
|
+
@data = @data.where("payer_name like ?", "%#{params[:q][:payer_name]}%")
|
103
|
+
end
|
104
|
+
|
105
|
+
if params[:q].present? && params[:q][:business].present?
|
106
|
+
@data = @data.joins(:business).where("educode_sales_businesses.name like ?", "%#{params[:q][:business]}%")
|
107
|
+
end
|
108
|
+
|
109
|
+
if params[:q].present? && params[:q][:number].present?
|
110
|
+
@data = @data.where("educode_sales_invoice_applies.number like ?", "%#{params[:q][:number]}%")
|
111
|
+
end
|
112
|
+
|
113
|
+
if params[:q].present? && params[:q][:amount].present?
|
114
|
+
@data = @data.where("educode_sales_invoice_applies.amount = ?", params[:q][:amount])
|
115
|
+
end
|
116
|
+
|
117
|
+
if params[:q].present? && params[:q][:staff_id].present?
|
118
|
+
@data = @data.where("educode_sales_invoice_applies.staff_id = ?", params[:q][:staff_id])
|
119
|
+
end
|
120
|
+
|
121
|
+
if params[:q].present? && params[:q][:created_at].present?
|
122
|
+
date = params[:q][:created_at].split(" - ")
|
123
|
+
@data = @data.where("educode_sales_invoice_applies.created_at > ? AND educode_sales_invoice_applies.created_at < ?", date[0] + " 00:00:00", date[1] + " 23:59:59")
|
124
|
+
end
|
125
|
+
|
126
|
+
if params[:q].present? && params[:q][:date_at].present?
|
127
|
+
date = params[:q][:date_at].split(" - ")
|
128
|
+
@data = @data.joins(:invoices).where("educode_sales_invoices.date_at > ? AND educode_sales_invoices.date_at < ?", date[0] + " 00:00:00", date[1] + " 23:59:59")
|
129
|
+
end
|
130
|
+
|
131
|
+
if params[:q].present? && params[:q][:school].present?
|
132
|
+
@data = @data.joins(business: :school).where("schools.name like ?", "%#{params[:q][:school]}%")
|
133
|
+
end
|
134
|
+
|
135
|
+
if params[:q].present? && params[:q][:invoice_number].present?
|
136
|
+
@data = @data.joins(:invoices).where("educode_sales_invoices.number like ?", "%#{params[:q][:invoice_number]}%")
|
137
|
+
end
|
138
|
+
|
139
|
+
if params[:q].present? && params[:q][:date_at].present?
|
140
|
+
date = params[:q][:date_at].split(" - ")
|
141
|
+
@data = @data.where("date_at BETWEEN ? AND ?", date[0], date[1])
|
142
|
+
end
|
143
|
+
if params[:q].present? && params[:q][:state].present?
|
144
|
+
if params[:q][:state] == '已认领'
|
145
|
+
@data = @data.having("claim_num > 0")
|
146
|
+
elsif params[:q][:state] == '待认领'
|
147
|
+
@data = @data.having("claim_num = 0 AND business_id IS NOT NULL")
|
148
|
+
elsif params[:q][:state] == '无对应合同'
|
149
|
+
@data = @data.having("claim_num = 0 AND business_id IS NULL")
|
150
|
+
end
|
151
|
+
|
152
|
+
end
|
153
|
+
if params[:q].present? && params[:q][:amount].present?
|
154
|
+
@data = @data.where(amount: params[:q][:amount])
|
155
|
+
end
|
156
|
+
|
157
|
+
if params[:sort].present? && params[:sort][:field]
|
158
|
+
@data = @data.order("#{params[:sort][:field]} #{params[:sort][:order]}")
|
159
|
+
else
|
160
|
+
@data = @data.order(created_at: :desc)
|
161
|
+
end
|
162
|
+
@data = @data.page(params[:page]).per(params[:limit])
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
def list
|
168
|
+
invoice_apply = InvoiceApply.find(params[:id])
|
169
|
+
@data = invoice_apply.invoices
|
170
|
+
@data = @data.order(created_at: :desc).page(params[:page]).per(params[:limit])
|
171
|
+
end
|
172
|
+
|
173
|
+
def new
|
174
|
+
render layout: false
|
175
|
+
end
|
176
|
+
|
177
|
+
def create
|
178
|
+
invoice_apply = InvoiceApply.find(params[:invoice_apply_id])
|
179
|
+
invoice = invoice_apply.invoices.new(invoice_params)
|
180
|
+
if invoice.save
|
181
|
+
render_success
|
182
|
+
else
|
183
|
+
render_failure invoice
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
def update
|
188
|
+
invoice = Invoice.find(params[:id])
|
189
|
+
if invoice.update(invoice_params)
|
190
|
+
render_success
|
191
|
+
else
|
192
|
+
render_failure invoice
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
def destroy
|
197
|
+
invoice = Invoice.find(params[:id])
|
198
|
+
if invoice.destroy
|
199
|
+
render_success
|
200
|
+
else
|
201
|
+
render_failure invoice
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
|
206
|
+
private
|
207
|
+
def apply_params
|
208
|
+
params.permit(:category, :is_tax_rebate, :ticket_at, :name, :taxpaper_number, :address, :phone, :bank, :bank_number)
|
209
|
+
end
|
210
|
+
|
211
|
+
def detail_params
|
212
|
+
params.permit(:category, :specification, :unit, :num, :price, :amount)
|
213
|
+
end
|
214
|
+
|
215
|
+
def invoice_params
|
216
|
+
params.permit(:number, :no_tax_amount, :taxt_amount, :amount, :date_at)
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
require_dependency "educode_sales/application_controller"
|
2
|
+
|
3
|
+
module EducodeSales
|
4
|
+
class MoneyPlanRecordsController < ApplicationController
|
5
|
+
|
6
|
+
def index
|
7
|
+
respond_to do |format|
|
8
|
+
format.html do
|
9
|
+
end
|
10
|
+
format.js do
|
11
|
+
end
|
12
|
+
format.json do
|
13
|
+
@money_plan_records = MoneyPlanRecord.left_joins(:money_plan_claims).group("educode_sales_money_plan_records.id").select("educode_sales_money_plan_records.*, COUNT(educode_sales_money_plan_claims.id) AS claim_num")
|
14
|
+
if @current_admin.is_admin?
|
15
|
+
else
|
16
|
+
level = @current_admin.role.role_areas.find_by(clazz: '回款管理').level
|
17
|
+
case level
|
18
|
+
when '自己'
|
19
|
+
@money_plan_records = @money_plan_records.where(staff_id: @current_admin.id)
|
20
|
+
when '区域'
|
21
|
+
school_ids = School.where(province: @current_admin.areas.pluck(:name)).pluck(:id) + StaffSchool.where(staff_id: @current_admin.id).pluck(:school_id)
|
22
|
+
b_ids = Business.where(school_id: school_ids).pluck(:id)
|
23
|
+
@money_plan_records = @money_plan_records.joins(:business).where("educode_sales_businesses.id in (?) OR educode_sales_money_plans.staff_id = ?", b_ids, @current_admin.id)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
if params[:q].present? && params[:q][:payer_name].present?
|
28
|
+
@money_plan_records = @money_plan_records.where("payer_name like ?", "%#{params[:q][:payer_name]}%")
|
29
|
+
end
|
30
|
+
|
31
|
+
if params[:q].present? && params[:q][:date_at].present?
|
32
|
+
date = params[:q][:date_at].split(" - ")
|
33
|
+
@money_plan_records = @money_plan_records.where("date_at BETWEEN ? AND ?", date[0], date[1])
|
34
|
+
end
|
35
|
+
if params[:q].present? && params[:q][:state].present?
|
36
|
+
if params[:q][:state] == '已认领'
|
37
|
+
@money_plan_records = @money_plan_records.having("claim_num > 0")
|
38
|
+
elsif params[:q][:state] == '待认领'
|
39
|
+
@money_plan_records = @money_plan_records.having("claim_num = 0 AND business_id IS NOT NULL")
|
40
|
+
elsif params[:q][:state] == '无对应合同'
|
41
|
+
@money_plan_records = @money_plan_records.having("claim_num = 0 AND business_id IS NULL")
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
if params[:q].present? && params[:q][:amount].present?
|
46
|
+
@money_plan_records = @money_plan_records.where(amount: params[:q][:amount])
|
47
|
+
end
|
48
|
+
|
49
|
+
if params[:sort].present? && params[:sort][:field]
|
50
|
+
@money_plan_records = @money_plan_records.order("#{params[:sort][:field]} #{params[:sort][:order]}")
|
51
|
+
else
|
52
|
+
@money_plan_records = @money_plan_records.order(created_at: :desc)
|
53
|
+
end
|
54
|
+
@money_plan_records = @money_plan_records.page(params[:page]).per(params[:limit])
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def add
|
60
|
+
render layout: false
|
61
|
+
end
|
62
|
+
|
63
|
+
def confirm_plan
|
64
|
+
@money_plan_record = MoneyPlanRecord.find(params[:id])
|
65
|
+
gon.money_plan_records = []
|
66
|
+
gon.money_plan_ids = []
|
67
|
+
gon.money_plan_claim_amount = []
|
68
|
+
@money_plan_claim = nil
|
69
|
+
@money_plan_claims = @money_plan_record.money_plan_claims.each_with_index do |d, i|
|
70
|
+
if i == 0
|
71
|
+
@money_plan_claim = d
|
72
|
+
end
|
73
|
+
gon.money_plan_records << [{value: d.money_plan_id.to_s, name: "#{d.money_plan.business&.number}/#{d.money_plan.business&.name}/#{d.money_plan.business&.school&.name}/ #{d.money_plan.business.last_follow_up&.actual_amount}万 / #{d.money_plan.date_at.to_s(:date)}"}]
|
74
|
+
gon.money_plan_ids << d.money_plan_id.to_s
|
75
|
+
gon.money_plan_claim_amount << [d.amount]
|
76
|
+
end
|
77
|
+
render layout: false
|
78
|
+
end
|
79
|
+
|
80
|
+
def create
|
81
|
+
business_id = Business.find_by(id: params[:business_id])&.id
|
82
|
+
record = MoneyPlanRecord.new(amount: params[:amount], payer_name: params[:payer_name], date_at: params[:date_at], staff_id: @current_admin.id, business_id: business_id)
|
83
|
+
if record.save
|
84
|
+
render_success
|
85
|
+
else
|
86
|
+
render_failure record
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def upload
|
91
|
+
xlsx = Roo::Spreadsheet.open(params[:file])
|
92
|
+
ods = xlsx.sheet(0)
|
93
|
+
rows = ods.last_row - 1
|
94
|
+
rows.times do |r| #行数
|
95
|
+
next unless ods.row(r+2)[0]
|
96
|
+
business_id = Business.find_by(number: ods.row(r+2)[3].to_s.strip)&.id
|
97
|
+
EducodeSales::MoneyPlanRecord.create(payer_name: ods.row(r+2)[0].to_s.strip, amount: ods.row(r+2)[1].to_s.strip, date_at: ods.row(r+2)[2].to_s.strip, business_id: business_id, staff_id: @current_admin.id) if business_id
|
98
|
+
end
|
99
|
+
|
100
|
+
render json: { succcess: true}
|
101
|
+
end
|
102
|
+
|
103
|
+
def confirm
|
104
|
+
money_plan_record = MoneyPlanRecord.find(params[:id])
|
105
|
+
money_plan_record.money_plan_claims.where.not(money_plan_id: params[:money_plan_ids]).delete_all
|
106
|
+
(params[:num].to_i + 1).times do |i|
|
107
|
+
claim = money_plan_record.money_plan_claims.find_or_initialize_by(money_plan_id: params[:money_plan_ids][i])
|
108
|
+
claim.amount = params["amount[#{i}]"]
|
109
|
+
claim.staff = @current_admin
|
110
|
+
claim.save
|
111
|
+
end
|
112
|
+
|
113
|
+
render_success
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -4,51 +4,30 @@ module EducodeSales
|
|
4
4
|
class MoneyPlansController < ApplicationController
|
5
5
|
|
6
6
|
def index
|
7
|
-
follow_up_ids = Business.pluck(:last_follow_up_id)
|
8
7
|
authorize! :read, MoneyPlan
|
9
8
|
respond_to do |format|
|
10
9
|
format.html do
|
11
|
-
common = Common.find_by(clazz: 'staff_type', name: '销售')
|
12
|
-
@staffs = Staff.joins(:user).where(job_type: common.id).map { |d| [d.user.real_name, d.id]}
|
13
10
|
end
|
14
11
|
format.json do
|
15
|
-
|
12
|
+
@money_plans = MoneyPlan.joins(:business).left_joins(:money_plan_claims).group("educode_sales_money_plans.id").select("educode_sales_money_plans.*, COUNT(educode_sales_money_plan_claims.id) AS claim_num")
|
16
13
|
if @current_admin.is_admin?
|
17
|
-
@money_plans = MoneyPlan.joins(:follow_up).where("educode_sales_follow_ups.clazz_id != ?", x_id).where(follow_up_id: follow_up_ids)
|
18
14
|
else
|
19
15
|
level = @current_admin.role.role_areas.find_by(clazz: '回款管理').level
|
20
16
|
case level
|
21
17
|
when '自己'
|
22
|
-
@money_plans =
|
18
|
+
@money_plans = @money_plans.where(staff_id: @current_admin.id)
|
23
19
|
when '区域'
|
24
|
-
a_ids = MoneyPlan.where(follow_up_id: follow_up_ids).where(staff_id: @current_admin.id).pluck(:follow_up_id)
|
25
20
|
school_ids = School.where(province: @current_admin.areas.pluck(:name)).pluck(:id) + StaffSchool.where(staff_id: @current_admin.id).pluck(:school_id)
|
26
|
-
b_ids = Business.where(school_id: school_ids).pluck(:
|
27
|
-
|
28
|
-
@money_plans = MoneyPlan.joins(:follow_up).where("educode_sales_follow_ups.clazz_id != ?", x_id).where(follow_up_id: ids)
|
29
|
-
else
|
30
|
-
@money_plans = MoneyPlan.joins(:follow_up).where("educode_sales_follow_ups.clazz_id != ?", x_id).where(follow_up_id: follow_up_ids)
|
21
|
+
b_ids = Business.where(school_id: school_ids).pluck(:id)
|
22
|
+
@money_plans = @money_plans.where("educode_sales_businesses.id in (?) OR educode_sales_money_plans.staff_id = ?", b_ids, @current_admin.id)
|
31
23
|
end
|
32
24
|
end
|
33
25
|
|
34
26
|
if params[:q].present? && params[:q][:business].present?
|
35
|
-
|
36
|
-
@money_plans = @money_plans.where(follow_up_id: follow_up_ids)
|
27
|
+
@money_plans = @money_plans.where("educode_sales_businesses.name like ?", "%#{params[:q][:business]}%")
|
37
28
|
end
|
38
29
|
if params[:q].present? && params[:q][:school].present?
|
39
|
-
|
40
|
-
follow_up_ids = Business.where(school_id: school_ids).pluck(:last_follow_up_id)
|
41
|
-
@money_plans = @money_plans.where(follow_up_id: follow_up_ids)
|
42
|
-
end
|
43
|
-
if params[:q].present? && params[:q][:staff_id].present?
|
44
|
-
@money_plans = @money_plans.where(staff_id: params[:q][:staff_id])
|
45
|
-
end
|
46
|
-
if params[:q].present? && params[:q][:clazz].present?
|
47
|
-
@money_plans = @money_plans.where(clazz: params[:q][:clazz])
|
48
|
-
end
|
49
|
-
if params[:q].present? && params[:q][:date].present?
|
50
|
-
date = params[:q][:date].split(" - ")
|
51
|
-
@money_plans = @money_plans.where("educode_sales_money_plans.date_at >= ? AND educode_sales_money_plans.date_at < ?", date[0], date[1] + '23:59:59')
|
30
|
+
@money_plans = @money_plans.joins(business: :school).where("schools.name like ?", "%#{params[:q][:school]}%")
|
52
31
|
end
|
53
32
|
|
54
33
|
if params[:sort].present? && params[:sort][:field]
|
@@ -56,10 +35,35 @@ module EducodeSales
|
|
56
35
|
else
|
57
36
|
@money_plans = @money_plans.order(date_at: :desc)
|
58
37
|
end
|
59
|
-
@total_amount = @money_plans.sum(:amount)
|
60
38
|
@money_plans = @money_plans.page(params[:page]).per(params[:limit])
|
61
39
|
end
|
62
40
|
end
|
63
41
|
end
|
42
|
+
|
43
|
+
def list
|
44
|
+
follow_up_ids = Business.pluck(:last_follow_up_id)
|
45
|
+
authorize! :read, MoneyPlan
|
46
|
+
respond_to do |format|
|
47
|
+
format.html do
|
48
|
+
common = Common.find_by(clazz: 'staff_type', name: '销售')
|
49
|
+
@staffs = Staff.joins(:user).where(job_type: common.id).map { |d| [d.user.real_name, d.id]}
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def add
|
56
|
+
render layout: false
|
57
|
+
end
|
58
|
+
|
59
|
+
def create
|
60
|
+
business = Business.find(params[:business_id])
|
61
|
+
data = []
|
62
|
+
(params[:num].to_i+1).times do |i|
|
63
|
+
business.money_plans.create(category: params["category[#{i}]"], amount: params["amount[#{i}]"], payment_clause: params["payment_clause[#{i}]"], date_at: params["date_at[#{i}]"], follow_up_id: business.last_follow_up_id, staff_id: @current_admin.id )
|
64
|
+
end
|
65
|
+
render_success
|
66
|
+
end
|
67
|
+
|
64
68
|
end
|
65
69
|
end
|
@@ -235,9 +235,9 @@ module EducodeSales
|
|
235
235
|
if params[:business_count_type] == 'money' || params[:business_count_type].blank?
|
236
236
|
data = provinces.map { |province|
|
237
237
|
if params[:business_type].blank?
|
238
|
-
Business.joins(:last_follow_up).where("educode_sales_businesses.department_id in (?)", School.joins(:departments).where(province: province).pluck("departments.id")).where("educode_sales_follow_ups.clazz_id != ? AND educode_sales_follow_ups.clazz_id != ?", x, o).sum(:
|
238
|
+
Business.joins(:last_follow_up).where("educode_sales_businesses.department_id in (?)", School.joins(:departments).where(province: province).pluck("departments.id")).where("educode_sales_follow_ups.clazz_id != ? AND educode_sales_follow_ups.clazz_id != ?", x, o).sum(:budget_amount).round(2)
|
239
239
|
else
|
240
|
-
Business.joins(:last_follow_up).where("educode_sales_businesses.department_id in (?)", School.joins(:departments).where(province: province).pluck("departments.id")).where("educode_sales_follow_ups.clazz_id in (?)", params[:business_type].split(",")).sum(:
|
240
|
+
Business.joins(:last_follow_up).where("educode_sales_businesses.department_id in (?)", School.joins(:departments).where(province: province).pluck("departments.id")).where("educode_sales_follow_ups.clazz_id in (?)", params[:business_type].split(",")).sum(:budget_amount).round(2)
|
241
241
|
end
|
242
242
|
}
|
243
243
|
if params[:sort_by].present?
|
@@ -157,7 +157,7 @@ module EducodeSales
|
|
157
157
|
private
|
158
158
|
|
159
159
|
def sales_detail_params
|
160
|
-
params.permit(:amount, :price, :total_price, :custom_clazz, :delivery_date, :product_catalog_id)
|
160
|
+
params.permit(:amount, :price, :total_price, :custom_clazz, :delivery_date, :product_catalog_id, :proprietorship)
|
161
161
|
end
|
162
162
|
|
163
163
|
end
|
@@ -9,8 +9,13 @@ module EducodeSales
|
|
9
9
|
last_follow = follow_up.business.follow_ups.where.not(id: follow_up.id).order("id desc").first
|
10
10
|
if last_follow.present? && last_follow.key_people_count > 0
|
11
11
|
@person = last_follow.key_person.last
|
12
|
-
|
13
|
-
|
12
|
+
if @person&.teacher.present?
|
13
|
+
gon.teacher = "t-#{@person.teacher_id}"
|
14
|
+
gon.teachers = { value: "t-#{@person.teacher_id}", name: @person.name }
|
15
|
+
else
|
16
|
+
gon.teacher = ""
|
17
|
+
gon.teachers = {}
|
18
|
+
end
|
14
19
|
end
|
15
20
|
end
|
16
21
|
@attitudes = Common.where(clazz: 'key_attitude').order("position").pluck(:name, :id)
|
@@ -18,6 +18,13 @@ module EducodeSales
|
|
18
18
|
has_many :business_levels, dependent: :destroy
|
19
19
|
has_many :business_watches, dependent: :destroy
|
20
20
|
has_many :business_histories, dependent: :destroy
|
21
|
+
has_many :money_plans
|
22
|
+
|
23
|
+
has_one :invoice_apply
|
24
|
+
has_many :invoice_details
|
25
|
+
has_many :sales_details
|
26
|
+
|
27
|
+
belongs_to :school
|
21
28
|
|
22
29
|
belongs_to :sourcable, :polymorphic => true, optional: true
|
23
30
|
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module EducodeSales
|
2
|
+
class InvoiceApply < ApplicationRecord
|
3
|
+
belongs_to :business
|
4
|
+
belongs_to :staff
|
5
|
+
belongs_to :take_ticket, class_name: 'Staff', optional: true
|
6
|
+
has_many :invoice_details
|
7
|
+
has_many :invoices
|
8
|
+
|
9
|
+
enum category: ['纸质专用发票', '纸质普通发票', '电子普通发票']
|
10
|
+
enum state: ['审核中', '已开票']
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module EducodeSales
|
2
|
+
class InvoiceDetail < ApplicationRecord
|
3
|
+
belongs_to :invoice_apply, optional: true
|
4
|
+
belongs_to :sale_detail, class_name: 'SalesDetail'
|
5
|
+
belongs_to :business
|
6
|
+
|
7
|
+
enum category: ['软件', '技术服务', '硬件', '装修服务', '咨询服务', '会议服务']
|
8
|
+
enum state: ['待开票', '已开票']
|
9
|
+
end
|
10
|
+
end
|