asadlive84

views.py file

Nov 7th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.11 KB | None | 0 0
  1. def get_pdf_file(request, customer_id, sys_type):
  2.     sys_type = customer_id
  3.     area = "pdf"
  4.     site_credit = site_credit1
  5.     time_now = timezone.now()
  6.     customers = get_object_or_404(CustomerInfo, pk=customer_id)
  7.  
  8.     due_taka_track = customers.duetaka_set.all()
  9.  
  10.     if due_taka_track == None:
  11.         due_taka_track = 0
  12.  
  13.     unpaid_taka = int(customers.customer_price -
  14.                       customers.customer_due_taka_info)
  15.     due_taka_track = customers.duetaka_set.all()
  16.  
  17.     sum_cost_taka = due_taka_track.aggregate(
  18.         sp=Sum('customer_due')).get('sp', 0)
  19.  
  20.     if sum_cost_taka == None:
  21.         sum_cost_taka = 0
  22.     total_paid_taka = sum_cost_taka + customers.customer_due_taka_info
  23.  
  24.     payment_status = 'complete'
  25.     payment_message = ' '
  26.     remain_taka='Full Paid '
  27.     remain_msg=''
  28.    
  29.  
  30.     if customers.customer_due_taka_info < customers.customer_price:
  31.         payment_status = 'incomplete'
  32.         payment_message = 'সম্পূর্ন টাকা পরিষোধ করা হয়নি'
  33.         remain_msg='টাকা বাকী আছে'
  34.         baki_ase="পাওনা আছে "
  35.  
  36.         remain_taka = customers.customer_price - customers.customer_due_taka_info
  37.    
  38.        
  39.  
  40.     context = {'customers': customers,
  41.     'sys_type': sys_type,
  42.     'area': area,
  43.     'site_credit': site_credit,
  44.     'site_name': 'Moon Telecom',
  45.     'sys_type': sys_type,
  46.     'due_taka_track': due_taka_track,
  47.     'total_paid_taka': total_paid_taka,
  48.     'payment_message': payment_message,
  49.     'time_now': time_now,
  50.     'unpaid_taka': unpaid_taka,
  51.     'payment_message': payment_message,
  52.     'remain_taka': remain_taka,
  53.     'sum_cost_taka': sum_cost_taka,
  54.     'remain_msg': remain_msg}
  55.  
  56.     html_string = render_to_string('shop/pdf_invoice.html', context).encode(encoding="UTF-8")
  57.     response = HttpResponse(content_type='application/pdf')
  58.    
  59.     response['Content-Disposition'] = 'inline; filename=invoice' + \
  60.         str(customers.id)+customers.customer_uid + customers.customer_name + '.pdf'
  61.    
  62.     HTML(string=html_string).write_pdf(response)
  63.     return response
Add Comment
Please, Sign In to add comment