Last active
July 28, 2023 07:19
-
-
Save Shankjbs571/113679e276ad88b88d7e13d46d3fed5d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.http import JsonResponse | |
import json | |
@csrf_exempt | |
def generate_pdf_Inspection_report(request): | |
jsonData = request.POST.get('jsonData') | |
# Parse the JSON string into a Python object | |
data = json.loads(jsonData) | |
# Access the values | |
location_code = data['location_code'] | |
location_type = data['location_type'] | |
designation = data['designation'] | |
dept = data['dept'] | |
created_on = data['created_on'] | |
selected_value = data['selectedValue'] | |
l=[] | |
if designation: | |
l = designation | |
# print("mydesigs",l) | |
elif location_type: | |
# DIVISION WISE | |
for x in location_type: | |
x1=x.split('-') | |
ins=list(models.Level_Desig.objects.exclude(delete_flag=True).filter(designation__icontains=x1[0]).values('designation').distinct('designation')) | |
#print(ins,'==============================================') | |
for i in ins: | |
l.append(i['designation']) | |
# END DIVISION WISE | |
elif location_code: | |
ins=list(models.railwayLocationMaster.objects.filter(Q(location_type_desc='DIVISION')|Q(location_type_desc='WORKSHOP')|Q(location_type_desc='STORE')|Q(location_type_desc='CONSTRUCTION'),parent_location_code__in=location_code).values('location_code', 'location_type')) | |
l=list(models.Level_Desig.objects.exclude(delete_flag=True).filter(rly_unit_id__in=(models.railwayLocationMaster.objects.filter(parent_location_code__in=location_code).values('rly_unit_code'))).values_list('designation',flat=True).distinct('designation')) | |
print("insdesig",l) | |
# END RAILWAY WISE | |
else: | |
list7=models.Level_Desig.objects.exclude(delete_flag=True).all().values('designation').order_by('designation') | |
list8=[] | |
for i in list7: | |
# print(i['designation'],'_________') | |
list8.append(i['designation']) | |
l = list8 | |
# print("mylist5555",l) | |
''' inspection report ''' | |
total_total_inspection = 0 | |
total_total_closed = 0 | |
total_total_open = 0 | |
total_total_item = 0 | |
total_total_item_pending = 0 | |
total_total_item_overdue = 0 | |
total_total_per_complied = 0 | |
''' inspection report mom ''' | |
mom_total_total_inspection = 0 | |
mom_total_total_closed = 0 | |
mom_total_total_open = 0 | |
mom_total_total_item = 0 | |
mom_total_total_item_pending = 0 | |
mom_total_total_item_overdue = 0 | |
mom_total_total_per_complied = 0 | |
''' Do letter data ''' | |
do_total_total_open = 0 | |
do_total_total_pending = 0 | |
do_total_total_closed = 0 | |
do_total_total_per_complied = 0 | |
''' TASK TRACKER ''' | |
task_total_total_open = 0 | |
total_total_task_assign = 0 | |
total_total_task_completed = 0 | |
task_total_total_per_complied = 0 | |
my_data = [] | |
ajaxname = selected_value | |
if ajaxname == 'Marked By Officer': | |
print("inside MarkedByOfficer") | |
# DATA FROM AJAX MarkedByOfficer | |
if created_on: | |
print("inside else") | |
for i in l: | |
print(i) | |
datefrom = datetime.strptime(created_on.split('to')[0].strip(),'%d/%m/%y') | |
dateto = datetime.strptime(created_on.split('to')[1].strip(),'%d/%m/%y') | |
desig_code = models.Level_Desig.objects.exclude(delete_flag=True).filter(designation = i)[0].designation_code | |
###############################3 INSPECTION REPORT ################################## | |
# total complaince | |
cursor = connection.cursor() | |
cursor.execute(''' SELECT count(distinct(A.inspection_no)) total_comp | |
FROM public.inspects_inspection_details A, | |
public.inspects_marked_officers B, | |
public.inspects_item_details D, | |
public.myadmin_level_desig E | |
where B.item_no_id=D.item_no and B.marked_to_id = E.designation_code and B.marked_to_id = %s | |
and B.status_flag != 0 and A.inspection_no = D.inspection_no_id and | |
(A.inspected_on >= %s and A.inspected_on <= %s)''',[desig_code,datefrom,dateto]) | |
total_inspection = cursor.fetchall() | |
total_total_inspection +=total_inspection[0][0] | |
cursor.close() | |
# pending | |
cursor = connection.cursor() | |
cursor.execute(''' SELECT count(distinct(A.inspection_no)) pending | |
FROM public.inspects_inspection_details A, | |
public.inspects_marked_officers B, | |
public.inspects_item_details D, | |
public.myadmin_level_desig E | |
where B.item_no_id=D.item_no and B.marked_to_id = E.designation_code and B.marked_to_id = %s | |
and B.status_flag in (1,2) and A.inspection_no = D.inspection_no_id and | |
(A.inspected_on >= %s and A.inspected_on <= %s)''',[desig_code,datefrom,dateto]) | |
total_open = cursor.fetchall() | |
total_total_open +=total_open[0][0] | |
# print("total_inspection7777777777total_open",total_open) | |
total_closed =total_inspection[0][0]-total_open[0][0] | |
total_total_closed+=total_closed | |
# total_item | |
cursor = connection.cursor() | |
cursor.execute(''' SELECT count(D.item_no) | |
FROM public.inspects_inspection_details A, | |
public.inspects_marked_officers B, | |
public.inspects_item_details D, | |
public.myadmin_level_desig E | |
where B.item_no_id=D.item_no and B.marked_to_id = E.designation_code and B.marked_to_id = %s | |
and A.inspection_no = D.inspection_no_id and | |
B.status_flag >0 and (A.inspected_on >= %s and A.inspected_on <= %s)''',[desig_code,datefrom,dateto]) | |
total_item = cursor.fetchall() | |
total_total_item +=total_item[0][0] | |
# total_item_pending | |
cursor = connection.cursor() | |
cursor.execute(''' SELECT count(D.item_no) | |
FROM public.inspects_inspection_details A, | |
public.inspects_marked_officers B, | |
public.inspects_item_details D, | |
public.myadmin_level_desig E | |
where B.item_no_id=D.item_no and B.marked_to_id = E.designation_code and B.marked_to_id = %s | |
and A.inspection_no = D.inspection_no_id and | |
B.status_flag in (1,2) and (A.inspected_on >= %s and A.inspected_on <= %s)''',[desig_code,datefrom,dateto]) | |
total_item_pending = cursor.fetchall() | |
total_total_item_pending +=total_item_pending[0][0] | |
# total_item_overdue | |
cursor = connection.cursor() | |
cursor.execute(''' SELECT count(*) | |
FROM public.inspects_inspection_details A, | |
public.inspects_marked_officers B, | |
public.inspects_item_details D, | |
public.myadmin_level_desig E | |
where B.item_no_id=D.item_no and B.marked_to_id = E.designation_code and B.marked_to_id = %s | |
and A.inspection_no = D.inspection_no_id and | |
B.status_flag in (1,2) and | |
D.target_date < now() and (A.inspected_on >= %s and A.inspected_on <= %s)''',[desig_code,datefrom,dateto]) | |
total_item_overdue = cursor.fetchall() | |
total_total_item_overdue +=total_item_overdue[0][0] | |
# %complied | |
try: | |
per_complied = ((total_item[0][0]-total_item_pending[0][0])/total_item[0][0])*100 | |
except: | |
per_complied = 0 | |
# ####################### MOM INSPECTION REPORT ######################################### | |
# total complaince | |
cursor = connection.cursor() | |
cursor.execute(''' SELECT count(distinct(A.insp_no)) total_comp | |
FROM public.mom_insp_details A, | |
public.mom_marked_members B, | |
public.mom_item_details D, | |
public.myadmin_level_desig E | |
where B.item_no_id=D.item_no and B.marked_to_id = E.designation_code and B.marked_to_id = %s | |
and B.status_flag != 0 and A.insp_no = D.insp_no_id ''',[desig_code]) | |
mom_total_inspection = cursor.fetchall() | |
mom_total_total_inspection +=mom_total_inspection[0][0] | |
cursor.close() | |
# total_closed | |
cursor = connection.cursor() | |
cursor.execute(''' SELECT count(distinct(A.insp_no)) total_closed | |
FROM public.mom_insp_details A, | |
public.mom_marked_members B, | |
public.mom_item_details D, | |
public.myadmin_level_desig E | |
where B.item_no_id=D.item_no and B.marked_to_id = E.designation_code and B.marked_to_id = %s | |
and B.status_flag = 4 and A.insp_no = D.insp_no_id''',[desig_code]) | |
mom_total_closed = cursor.fetchall() | |
mom_total_total_closed +=mom_total_closed[0][0] | |
# pending | |
cursor = connection.cursor() | |
cursor.execute(''' SELECT count(distinct(A.insp_no)) pending | |
FROM public.mom_insp_details A, | |
public.mom_marked_members B, | |
public.mom_item_details D, | |
public.myadmin_level_desig E | |
where B.item_no_id=D.item_no and B.marked_to_id = E.designation_code and B.marked_to_id = %s | |
and B.status_flag in (1,2) and A.insp_no = D.insp_no_id ''',[desig_code]) | |
mom_total_open = cursor.fetchall() | |
mom_total_total_open +=mom_total_open[0][0] | |
# print("total_inspection7777777777total_open",mom_total_open) | |
# total_item | |
cursor = connection.cursor() | |
cursor.execute(''' SELECT count(*) FROM public.mom_insp_details A, | |
public.mom_marked_members B, | |
public.mom_item_details D, | |
public.myadmin_level_desig E | |
where B.item_no_id=D.item_no and B.marked_to_id = E.designation_code and B.marked_to_id = %s | |
and A.insp_no = D.insp_no_id and | |
D.status_flag >0''',[desig_code]) | |
mom_total_item = cursor.fetchall() | |
mom_total_total_item +=mom_total_item[0][0] | |
# total_item_pending | |
cursor = connection.cursor() | |
cursor.execute(''' SELECT count(*) FROM public.mom_insp_details A, | |
public.mom_marked_members B, | |
public.mom_item_details D, | |
public.myadmin_level_desig E | |
where B.item_no_id=D.item_no and B.marked_to_id = E.designation_code and B.marked_to_id = %s | |
and A.insp_no = D.insp_no_id and | |
D.status_flag in (1,2,3) ''',[desig_code]) | |
mom_total_item_pending = cursor.fetchall() | |
mom_total_total_item_pending +=mom_total_item_pending[0][0] | |
# total_item_overdue | |
cursor = connection.cursor() | |
cursor.execute(''' SELECT count(*) FROM public.mom_insp_details A, | |
public.mom_marked_members B, | |
public.mom_item_details D, | |
public.myadmin_level_desig E | |
where B.item_no_id=D.item_no and B.marked_to_id = E.designation_code and B.marked_to_id = %s | |
and A.insp_no = D.insp_no_id and | |
D.status_flag in (1,2,3) ''',[desig_code]) | |
mom_total_item_overdue = cursor.fetchall() | |
mom_total_total_item_overdue +=mom_total_item_overdue[0][0] | |
# %complied | |
try: | |
mom_per_complied = ((mom_total_item-mom_total_item_pending)/mom_total_item)*100 | |
except: | |
mom_per_complied = 0 | |
# DO LETTER | |
# TOTAL OPEN | |
do_total_open=m4.do_act.objects.filter(desig_id_id = desig_code).count() | |
do_total_total_open += do_total_open | |
# TOTAL PENDING | |
do_total_pending=m4.do_act.objects.filter(desig_id_id = desig_code,status_flag=False).count() | |
do_total_total_pending += do_total_pending | |
# TOTAL CLOSED | |
do_total_closed=m4.do_act.objects.filter(desig_id_id = desig_code,status_flag=True).count() | |
do_total_total_closed += do_total_closed | |
# per complied | |
try: | |
do_per_complied = (do_total_closed / do_total_open) * 100 | |
except: | |
do_per_complied = 0 | |
''' TASK TRACKER ''' | |
# total task tracker assign data | |
# task_assigned_insp = m1.target_compliance.objects.filter(marked_no__item_no__inspection_no__inspection_officer__rly_unit__location_code = i, task_flag=1).exclude(status_flag = 3).count() | |
# task_assigned_tracker = m1.target_compliance.objects.filter(assigned_by__rly_unit__location_code = i, task_flag=2).exclude(status_flag = 3).count() | |
task_assigned = m1.target_compliance.objects.filter(pending_with__designation_code = desig_code).exclude(status_flag = 3).count() | |
total_total_task_assign += task_assigned | |
# total task tracker completed data apeksha:7005 | |
# task_completed_insp = m1.target_compliance.objects.filter(marked_no__item_no__inspection_no__inspection_officer__rly_unit__location_code = i, task_flag=1,status_flag = 3).count() | |
task_completed = m1.target_compliance.objects.filter(pending_with__designation_code = desig_code, status_flag = 3).count() | |
# task_completed = task_completed_insp + task_completed_tracker | |
total_total_task_completed += task_completed | |
# total task tracker open data | |
totol_open = task_assigned+task_completed | |
task_total_total_open += totol_open | |
try: | |
task_per_complied = (task_completed / totol_open) * 100 | |
except: | |
task_per_complied = 0 | |
my_data.append({'rly':i,"total_inspection":total_inspection[0][0],"total_closed":total_closed, | |
"total_open":total_open[0][0],"total_item":total_item[0][0],"total_item_pending":total_item_pending[0][0], | |
'total_item_overdue':total_item_overdue[0][0],"per_complied":per_complied,"mom_total_inspection":mom_total_inspection[0][0],"mom_total_closed":mom_total_closed[0][0], | |
"mom_total_open":mom_total_open[0][0],"mom_total_item":mom_total_item[0][0],"mom_total_item_pending":mom_total_item_pending[0][0], | |
'mom_total_item_overdue':mom_total_item_overdue[0][0],"mom_per_complied":mom_per_complied,'do_total_open':do_total_open, | |
'do_total_pending':do_total_pending,'do_total_closed':do_total_closed, | |
'do_per_complied':do_per_complied,'task_assigned':task_assigned,"task_completed":task_completed, | |
'totol_open':totol_open,'task_per_complied':task_per_complied}) | |
try: | |
total_total_per_complied = ((total_total_item-total_total_item_pending)/total_total_item)*100 | |
except: | |
total_total_per_complied = 0 | |
try: | |
mom_total_total_per_complied = ((mom_total_total_item-mom_total_total_item_pending)/mom_total_total_item)*100 | |
except: | |
mom_total_total_per_complied = 0 | |
try: | |
do_total_total_per_complied = ((do_total_total_closed)/do_total_total_open)*100 | |
except: | |
do_total_total_per_complied = 0 | |
try: | |
task_total_total_per_complied = ((total_total_task_completed)/task_total_total_open)*100 | |
except: | |
task_total_total_per_complied = 0 | |
# print("mydata",total_total_item_overdue) | |
''' | |
return ({'rly_list':my_data,'total_total_inspection':total_total_inspection,"total_total_closed":total_total_closed, | |
"total_total_open":total_total_open,"total_total_item":total_total_item,"total_total_item_pending":total_total_item_pending, | |
"total_total_item_overdue":total_total_item_overdue,"total_total_per_complied":total_total_per_complied,'mom_total_total_inspection':mom_total_total_inspection,"mom_total_total_closed":mom_total_total_closed, | |
"mom_total_total_open":mom_total_total_open,"mom_total_total_item":mom_total_total_item,"mom_total_total_item_pending":mom_total_total_item_pending, | |
"mom_total_total_item_overdue":mom_total_total_item_overdue,"mom_total_total_per_complied":mom_total_total_per_complied,'do_total_total_open':do_total_total_open, | |
'do_total_total_pending':do_total_total_pending,'do_total_total_closed':do_total_total_closed, | |
'do_total_total_per_complied':do_total_total_per_complied,"task_total_total_open":task_total_total_open, | |
'total_total_task_assign':total_total_task_assign,'total_total_task_completed':total_total_task_completed, | |
'task_total_total_per_complied':task_total_total_per_complied}, safe=False) | |
''' | |
# return JsonResponse({'message': 'Data inside Marked by Officer'}) | |
# Prepare the context for rendering the PDF template | |
data = {'rly_list':my_data,'total_total_inspection':total_total_inspection,"total_total_closed":total_total_closed, | |
"total_total_open":total_total_open,"total_total_item":total_total_item,"total_total_item_pending":total_total_item_pending, | |
"total_total_item_overdue":total_total_item_overdue,"total_total_per_complied":total_total_per_complied,'mom_total_total_inspection':mom_total_total_inspection,"mom_total_total_closed":mom_total_total_closed, | |
"mom_total_total_open":mom_total_total_open,"mom_total_total_item":mom_total_total_item,"mom_total_total_item_pending":mom_total_total_item_pending, | |
"mom_total_total_item_overdue":mom_total_total_item_overdue,"mom_total_total_per_complied":mom_total_total_per_complied,'do_total_total_open':do_total_total_open, | |
'do_total_total_pending':do_total_total_pending,'do_total_total_closed':do_total_total_closed, | |
'do_total_total_per_complied':do_total_total_per_complied,"task_total_total_open":task_total_total_open, | |
'total_total_task_assign':total_total_task_assign,'total_total_task_completed':total_total_task_completed, | |
'task_total_total_per_complied':task_total_total_per_complied} | |
context = { | |
'location_code': location_code, | |
'location_type': location_type, | |
'designation': designation, | |
'dept': dept, | |
'created_on': created_on, | |
'selected_value': selected_value, | |
'data': data | |
} | |
# Render the HTML template as a string | |
pdf = render_to_pdf('new_inspection_report_pdf.html', context) | |
# print("Rendering$$$$$$$$$$$$$$$$$$$$$$$$$$$$4") | |
# Return the PDF as a response | |
return HttpResponse(pdf, content_type='application/pdf') | |
return HttpResponse(result) | |
else: | |
# DATA FROM AJAX issues By Officer | |
if created_on: | |
datefrom = datetime.strptime(created_on.split('to')[0].strip(),'%d/%m/%y') | |
dateto = datetime.strptime(created_on.split('to')[1].strip(),'%d/%m/%y') | |
for i in l: | |
desig_code = models.Level_Desig.objects.exclude(delete_flag=True).filter(designation = i)[0].designation_code | |
# print("desig_codedesig_codedesig_codedesig_codedesig_code",desig_code) | |
# total_inspection=m1.Inspection_details.objects.filter(~Q(status_flag=0),inspection_officer=desig_code).count() | |
# total inspection notes (passed) | |
cursor = connection.cursor() | |
cursor.execute(''' SELECT count( DISTINCT A.inspection_no) total_inspection | |
FROM public.inspects_inspection_details A, | |
public.myadmin_level_desig B | |
where A.inspection_officer_id = B.designation_code and A.status_flag!=0 and | |
A.inspection_officer_id = %s and | |
(A.inspected_on >= %s and A.inspected_on <= %s) ''',[desig_code,datefrom,dateto]) | |
total_inspection = cursor.fetchall() | |
total_total_inspection +=total_inspection[0][0] | |
cursor.close() | |
# print("total_inspection45",total_inspection) | |
# total_closed (passed) | |
cursor = connection.cursor() | |
cursor.execute(''' SELECT count( DISTINCT A.inspection_no) total_closed | |
FROM public.inspects_inspection_details A, | |
public.myadmin_level_desig B | |
where A.inspection_officer_id = B.designation_code and A.status_flag=4 and | |
A.inspection_officer_id = %s and | |
(A.inspected_on >= %s and A.inspected_on <= %s) ''',[desig_code,datefrom,dateto]) | |
total_closed = cursor.fetchall() | |
total_total_closed +=total_closed[0][0] | |
cursor.close() | |
# pending inspection report (passed) | |
cursor = connection.cursor() | |
cursor.execute(''' SELECT count( DISTINCT A.inspection_no) total_open | |
FROM public.inspects_inspection_details A, | |
public.myadmin_level_desig B | |
where A.inspection_officer_id = B.designation_code and A.status_flag between 1 and 3 and | |
A.inspection_officer_id = %s and | |
(A.inspected_on >= %s and A.inspected_on <= %s) ''',[desig_code,datefrom,dateto]) | |
total_open = cursor.fetchall() | |
total_total_open +=total_open[0][0] | |
cursor.close() | |
# total_item | |
cursor = connection.cursor() | |
cursor.execute(''' SELECT count( distinct B.item_no_id) total_item | |
FROM public.inspects_inspection_details A, | |
public.inspects_marked_officers B, | |
public.inspects_item_details D | |
where A.status_flag>0 and | |
B.item_no_id=D.item_no and | |
A.inspection_no = D.inspection_no_id and D.status_flag >0 and A.inspection_officer_id = %s and | |
(A.inspected_on >= %s and A.inspected_on <= %s) ''',[desig_code,datefrom,dateto]) | |
total_item = cursor.fetchall() | |
total_total_item +=total_item[0][0] | |
cursor.close() | |
# total_item_pending | |
cursor = connection.cursor() | |
cursor.execute(''' SELECT count( distinct B.item_no_id) total_item | |
FROM public.inspects_inspection_details A, | |
public.inspects_marked_officers B, | |
public.inspects_item_details D | |
where A.status_flag between 1 and 3 and | |
B.item_no_id=D.item_no and | |
A.inspection_no = D.inspection_no_id and D.status_flag between 1 and 3 and A.inspection_officer_id = %s and | |
(A.inspected_on >= %s and A.inspected_on <= %s) ''',[desig_code,datefrom,dateto]) | |
total_item_pending = cursor.fetchall() | |
total_total_item_pending +=total_item_pending[0][0] | |
cursor.close() | |
# total_item_overdue | |
cursor = connection.cursor() | |
cursor.execute(''' SELECT count( distinct B.item_no_id) total_item | |
FROM public.inspects_inspection_details A, | |
public.inspects_marked_officers B, | |
public.inspects_item_details D | |
where B.item_no_id=D.item_no and A.status_flag between 1 and 4 and | |
A.inspection_no = D.inspection_no_id and D.status_flag between 1 and 3 and | |
D.target_date < now() and A.inspection_officer_id = %s and | |
(A.inspected_on >= %s and A.inspected_on <= %s) ''',[desig_code,datefrom,dateto]) | |
total_item_overdue = cursor.fetchall() | |
total_total_item_overdue +=total_item_overdue[0][0] | |
cursor.close() | |
# %complied | |
try: | |
per_complied = ((total_item[0][0]-total_item_pending[0][0])/total_item[0][0])*100 | |
except: | |
per_complied = 0 | |
# ####################### MOM INSPECTION REPORT ######################################### | |
# total complaince | |
cursor = connection.cursor() | |
cursor.execute(''' SELECT count( DISTINCT A.insp_no) total_inspection | |
FROM public.mom_insp_details A, | |
public.myadmin_level_desig B | |
where A.mom_officer_id = B.designation_code and A.status_flag!=0 and | |
A.mom_officer_id = %s and (A.mom_date >= %s and A.mom_date <= %s) ''',[desig_code,datefrom,dateto]) | |
mom_total_inspection = cursor.fetchall() | |
mom_total_total_inspection +=mom_total_inspection[0][0] | |
cursor.close() | |
# total_closed | |
cursor = connection.cursor() | |
cursor.execute(''' SELECT count( DISTINCT A.insp_no) total_closed | |
FROM public.mom_insp_details A, | |
public.myadmin_level_desig B | |
where A.mom_officer_id = B.designation_code and A.status_flag=4 and | |
A.mom_officer_id = %s and (A.mom_date >= %s and A.mom_date <= %s) ''',[desig_code,datefrom,dateto]) | |
mom_total_closed = cursor.fetchall() | |
mom_total_total_closed +=mom_total_closed[0][0] | |
# pending | |
cursor = connection.cursor() | |
cursor.execute(''' SELECT count( DISTINCT A.insp_no) total_open | |
FROM public.mom_insp_details A, | |
public.myadmin_level_desig B | |
where A.mom_officer_id = B.designation_code and A.status_flag between 1 and 3 and | |
A.mom_officer_id = %s and (A.mom_date >= %s and A.mom_date <= %s) ''',[desig_code,datefrom,dateto]) | |
mom_total_open = cursor.fetchall() | |
mom_total_total_open +=mom_total_open[0][0] | |
# print("total_inspection7777777777total_open",mom_total_open) | |
# total_item | |
cursor = connection.cursor() | |
cursor.execute(''' SELECT count( distinct D.item_no) total_item | |
FROM public.mom_insp_details A, | |
public.mom_item_details D | |
where A.status_flag>0 and D.item_heading is not null and | |
A.insp_no = D.insp_no_id and D.status_flag >0 and A.mom_officer_id = %s and (A.mom_date >= %s and A.mom_date <= %s) ''',[desig_code,datefrom,dateto]) | |
mom_total_item = cursor.fetchall() | |
mom_total_total_item +=mom_total_item[0][0] | |
# total_item_pending | |
cursor = connection.cursor() | |
cursor.execute(''' SELECT count( distinct B.item_no_id) total_item | |
FROM public.mom_insp_details A, | |
public.mom_marked_members B, | |
public.mom_item_details D | |
where A.status_flag between 1 and 3 and | |
B.item_no_id=D.item_no and | |
A.insp_no = D.insp_no_id and D.status_flag between 1 and 3 and A.mom_officer_id = %s and (A.mom_date >= %s and A.mom_date <= %s)''',[desig_code,datefrom,dateto]) | |
mom_total_item_pending = cursor.fetchall() | |
mom_total_total_item_pending +=mom_total_item_pending[0][0] | |
# total_item_overdue | |
cursor = connection.cursor() | |
cursor.execute(''' SELECT count( distinct B.item_no_id) total_item | |
FROM public.mom_insp_details A, | |
public.mom_marked_members B, | |
public.mom_item_details D | |
where B.item_no_id=D.item_no and A.status_flag between 1 and 4 and | |
A.insp_no = D.insp_no_id and D.status_flag between 1 and 3 and | |
D.target_date < now() and A.mom_officer_id = %s and (A.mom_date >= %s and A.mom_date <= %s) ''',[desig_code,datefrom,dateto]) | |
mom_total_item_overdue = cursor.fetchall() | |
mom_total_total_item_overdue +=mom_total_item_overdue[0][0] | |
# %complied | |
try: | |
mom_per_complied = ((mom_total_item-mom_total_item_pending)/mom_total_item)*100 | |
except: | |
mom_per_complied = 0 | |
# DO LETTER OFFICER WISE ----------------------------------------------------------- | |
# user = request.user | |
dol=list(m4.do_upload.objects.filter(desig_id_id=desig_code).values_list('id',flat = True)) | |
# TOTAL OPEN | |
do_total_open=m4.do_act.objects.filter(id_upload__in = dol).count() | |
do_total_total_open += do_total_open | |
# TOTAL PENDING | |
do_total_pending=m4.do_act.objects.filter(id_upload__in = dol,status_flag=False).count() | |
do_total_total_pending += do_total_pending | |
# TOTAL CLOSED | |
do_total_closed=m4.do_act.objects.filter(id_upload__in = dol,status_flag=True).count() | |
do_total_total_closed += do_total_closed | |
# per complied | |
try: | |
do_per_complied = (do_total_closed / do_total_open) * 100 | |
except: | |
do_per_complied = 0 | |
# do_total_total_per_complied +=do_per_complied | |
''' TASK TRACKER ''' | |
# total task tracker assign data | |
# task_assigned_insp = m1.target_compliance.objects.filter(marked_no__item_no__inspection_no__inspection_officer__rly_unit__location_code = i, task_flag=1).exclude(status_flag = 3).count() | |
task_assigned = m1.target_compliance.objects.filter(assigned_by__designation_code = desig_code).exclude(status_flag = 3).count() | |
# task_assigned = task_assigned_insp+task_assigned_tracker | |
total_total_task_assign += task_assigned | |
# total task tracker completed data | |
# task_completed_insp = m1.target_compliance.objects.filter(marked_no__item_no__inspection_no__inspection_officer__rly_unit__location_code = i, task_flag=1,status_flag = 3).count() | |
task_completed = m1.target_compliance.objects.filter(assigned_by__designation_code = desig_code, status_flag = 3).count() | |
# task_completed = task_completed_insp + task_completed_tracker | |
total_total_task_completed += task_completed | |
# total task tracker open data | |
totol_open = task_assigned+task_completed | |
task_total_total_open += totol_open | |
try: | |
task_per_complied = (task_completed / totol_open) * 100 | |
except: | |
task_per_complied = 0 | |
my_data.append({'rly':i,"total_inspection":total_inspection[0][0],"total_closed":total_closed[0][0], | |
"total_open":total_open[0][0],"total_item":total_item[0][0],"total_item_pending":total_item_pending[0][0], | |
'total_item_overdue':total_item_overdue[0][0],"per_complied":per_complied,"mom_total_inspection":mom_total_inspection[0][0],"mom_total_closed":mom_total_closed[0][0], | |
"mom_total_open":mom_total_open[0][0],"mom_total_item":mom_total_item[0][0],"mom_total_item_pending":mom_total_item_pending[0][0], | |
'mom_total_item_overdue':mom_total_item_overdue[0][0],"mom_per_complied":mom_per_complied,'do_total_open':do_total_open, | |
'do_total_pending':do_total_pending,'do_total_closed':do_total_closed, | |
'do_per_complied':do_per_complied,'task_assigned':task_assigned,"task_completed":task_completed, | |
'totol_open':totol_open,'task_per_complied':task_per_complied}) | |
try: | |
total_total_per_complied = ((total_total_item-total_total_item_pending)/total_total_item)*100 | |
except: | |
total_total_per_complied = 0 | |
try: | |
mom_total_total_per_complied = ((mom_total_total_item-mom_total_total_item_pending)/mom_total_total_item)*100 | |
except: | |
mom_total_total_per_complied = 0 | |
try: | |
do_total_total_per_complied = ((do_total_total_closed)/do_total_total_open)*100 | |
except: | |
do_total_total_per_complied = 0 | |
try: | |
task_total_total_per_complied = ((total_total_task_completed)/task_total_total_open)*100 | |
except: | |
task_total_total_per_complied = 0 | |
data={'rly_list':my_data,'total_total_inspection':total_total_inspection,"total_total_closed":total_total_closed, | |
"total_total_open":total_total_open,"total_total_item":total_total_item,"total_total_item_pending":total_total_item_pending, | |
"total_total_item_overdue":total_total_item_overdue,"total_total_per_complied":total_total_per_complied, | |
'mom_total_total_inspection':mom_total_total_inspection,"mom_total_total_closed":mom_total_total_closed, | |
"mom_total_total_open":mom_total_total_open,"mom_total_total_item":mom_total_total_item,"mom_total_total_item_pending":mom_total_total_item_pending, | |
"mom_total_total_item_overdue":mom_total_total_item_overdue,"mom_total_total_per_complied":mom_total_total_per_complied,'do_total_total_open':do_total_total_open, | |
'do_total_total_pending':do_total_total_pending,'do_total_total_closed':do_total_total_closed, | |
'do_total_total_per_complied':do_total_total_per_complied,"task_total_total_open":task_total_total_open, | |
'total_total_task_assign':total_total_task_assign,'total_total_task_completed':total_total_task_completed, | |
'task_total_total_per_complied':task_total_total_per_complied} | |
context = { | |
'location_code': location_code, | |
'location_type': location_type, | |
'designation': designation, | |
'dept': dept, | |
'created_on': created_on, | |
'selected_value': selected_value, | |
'data': data | |
} | |
# Render the HTML template as a string | |
pdf = render_to_pdf('new_inspection_report_pdf.html', context) | |
#print("Rendering$$$$$$$$$$$$$$$$$$$$$$$$$$$$4") | |
# Return the PDF as a response | |
return HttpResponse(pdf, content_type='application/pdf') | |
return HttpResponse(result) | |
return JsonResponse({'message': 'Data received in Issues by officer'}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment