SELECT DRAGON COMPANIES ID DRAGON COMPANIES COMPANY_NAME DRAGON COMPAN

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
"""
SELECT
"DRAGON"."COMPANIES"."ID",
"DRAGON"."COMPANIES"."COMPANY_NAME",
"DRAGON"."COMPANIES"."ACTUAL_ADDRESS",
"DRAGON"."COMPANIES"."REGISTRATION_DATE",
"DRAGON"."COMPANIES"."CLIENT_ID",
"DRAGON"."COMPANIES"."VENDOR_ID",
"DRAGON"."COMPANIES"."INSURANCE_ID",
"DRAGON"."COMPANIES"."ORGANIZATION_TYPE",
"DRAGON"."COMPANIES"."LAW_ADDRESS",
"DRAGON"."COMPANIES"."ACTIVE",
"DRAGON"."COMPANIES"."COMPANY_FULL_NAME",
"DRAGON"."COMPANIES"."REAL_ACTUAL_ADDR",
"DRAGON"."COMPANIES"."REAL_LAW_ADDR",
"DRAGON"."COMPANIES"."POST_ADDR",
"DRAGON"."COMPANIES"."REAL_POST_ADDR",
"DRAGON"."EXTEDIT_FILLS"."ID",
"DRAGON"."EXTEDIT_FILLS"."EXTEDIT_ID",
"DRAGON"."EXTEDIT_FILLS"."TEXT"
FROM
"DRAGON"."COMPANIES"
INNER JOIN
"DRAGON"."DEALINGS"
ON
(
"DRAGON"."COMPANIES"."ID" = "DRAGON"."DEALINGS"."CLIENT_ID"
)
INNER JOIN
"DRAGON"."EXTEDIT_FILLS"
ON
(
"DRAGON"."COMPANIES"."ORGANIZATION_TYPE" = "DRAGON"."EXTEDIT_FILLS"."ID"
)
WHERE
"DRAGON"."DEALINGS"."MANAGER_ID" = '10694'
ORDER BY
"DRAGON"."COMPANIES"."ID"
DESC
"""
dealing_filter = dict()
condition = dict()
if request.method == 'POST':
search = request.POST.get('search', None)
if search is not None:
if search.isdigit():
condition['dealings__dealing_number__startswith'] = search
dealing_filter['dealing_number__startswith']=search
else:
condition['company_full_name__icontains'] = search
companies_data = Companies.objects.select_related().filter(dealings__manager_id=request.user_id, **dict(condition))
current_quarter_data = current_quarter()
quarter = [i['quarter'] for i in current_quarter_data]
year = [i['year'] for i in current_quarter_data]
for item in companies_data:
item.dealings_all = item.dealings_set.select_related().filter(manager_id=request.user_id, **dict(dealing_filter))
for equipments in item.dealings_all:
equipments.eq_list = equipments.equipments_set.select_related().all()
for graph in equipments.eq_list:
try:
#piece = GraphPieces.objects.filter(eq_id=graph.id).latest('id')
graph.graphs = Graphs.objects.filter(piece_id=graph.active_piece).latest('id')
except:
pass
#print u'For graph %s not rows' % graph.id
if item.finance_set.filter(quarter__in=quarter, year__in=year).count() >= 4:
item.finance_status = True
paginator = Paginator(companies_data, 500)