\d+)/$', docs.get_doc, name='customer_license_get_doc'),
url(r'^robokassa/result/$', license.payment_result, name='robokassa_result'),
url(r'^robokassa/success/$', license.payment_success, name='robokassa_success'),
url(r'^robokassa/fail/$', license.payment_fail, name='robokassa_fail'),
diff --git a/project/customer/views/docs.py b/project/customer/views/docs.py
new file mode 100644
index 0000000..e519e2c
--- /dev/null
+++ b/project/customer/views/docs.py
@@ -0,0 +1,102 @@
+# -*- coding: utf-8 -*-
+import os
+import re
+
+from django.conf import settings
+from django.http import Http404, HttpResponseRedirect, HttpResponseForbidden, HttpResponse
+
+from xlwt import easyxf
+from xlrd import open_workbook
+from xlutils.copy import copy
+from pytils.numeral import rubles
+
+from ..models import License
+
+
+XLS_ROOT = os.path.join(settings.TEMPLATE_DIRS[0], 'xls')
+
+
+def get_doc(request, order_num=None):
+ if not request.user.is_authenticated():
+ raise HttpResponseForbidden
+
+ license = License.objects.get(pk=order_num)
+ pm = license.payform
+ data = request.user.profile
+ if pm == 0:
+ tmp_name = 'bill.xls'
+ file_name = "Invoice No.%s.xls" % (order_num,)
+ elif pm == 2:
+ tmp_name = '4pd.xls'
+ file_name = "Kvitanciya na oplatu zakaza No.%s.xls" % (order_num,)
+ else:
+ raise Http404()
+
+ response = HttpResponse(mimetype="application/vnd.ms-excel")
+ response['Content-Disposition'] = 'attachment; filename=%s' % file_name
+
+ rb = open_workbook(os.path.join(XLS_ROOT, tmp_name), on_demand=True, formatting_info=True)
+ wb = copy(rb)
+ ws = wb.get_sheet(0)
+
+ # отключить колонтитулы
+ ws.show_headers = 0
+ ws.print_headers = 0
+ ws.header_str = ''
+ ws.footer_str = ''
+
+ if pm == 0: # заполняем счет
+ style0 = easyxf('font: name Times New Roman, height 280, bold True;')
+ style0_center = easyxf('font: name Times New Roman, height 280, bold True; align: horiz center')
+ style1 = easyxf('font: name Times New Roman, height 180;')
+ style2 = easyxf('font: name Times New Roman, height 180, bold True;')
+ style3 = easyxf('font: name Times New Roman, height 180;'
+ 'border: top thin, left thin, right thin, bottom thin;'
+ )
+ style4 = easyxf('font: name Times New Roman, height 180, bold True;'
+ 'border: top thin, left thin, right thin, bottom thin;'
+ )
+ style4.num_format_str = "#,##0.00"
+
+ ws.write(11, 0, u"СЧЕТ № %s от %s" % (order_num, license.order_date.strftime('%d.%m.%Y')), style0_center)
+ ws.write(13, 0, u"Покупатель: %s" % data.name, style1)
+ ws.write(16, 2, u"Использование сервиса Dokumentor сроком %s" % (license.get_term()), style3)
+
+ style3.num_format_str = "#,##0.00"
+
+ ws.write(16, 36, license.pay_sum, style3)
+ ws.write(16, 44, license.pay_sum, style3)
+ ws.write(17, 44, license.pay_sum, style4)
+ ws.write(19, 44, license.pay_sum, style4)
+ ws.write(21, 0, u"Всего наименование 1, на сумму %s,00 руб." % license.pay_sum, style1)
+ ws.write(23, 0, u"%s." % rubles(license.pay_sum).capitalize(), style2)
+
+ ws.insert_bitmap(os.path.join(XLS_ROOT, 'stamp.bmp'), 25, 12, y=3, scale_x=1, scale_y=1.1)
+
+ elif pm == 2: # заполняем квитанцию
+ style0 = easyxf('font: name Times New Roman, height 160, bold True;'
+ 'border: bottom thin;'
+ )
+ style1 = easyxf('font: name Times New Roman, height 160, bold True;'
+ 'border: bottom thin;'
+ 'align: horiz center;'
+ )
+
+ # заполняем оригинал
+ ws.write(11, 4, u"Использование сервиса Dokumentor сроком %s" % (license.get_term()), style1)
+ ws.write(13, 13, data.get_boss_fio(), style0)
+ ws.write(14, 13, re.sub("^\s+|\n|\r|\s+$", ' ', data.address), style0)
+ ws.write(15, 11, license.pay_sum, style1)
+
+ # заполняем копию
+ ws.write(31, 4, u"Использование сервиса Dokumentor сроком %s" % (license.get_term()), style1)
+ ws.write(33, 13, data.get_boss_fio(), style0)
+ ws.write(34, 13, re.sub("^\s+|\n|\r|\s+$", ' ', data.address), style0)
+ ws.write(35, 11, license.pay_sum, style1)
+
+ else:
+ raise Http404()
+
+ wb.save(response)
+
+ return response
diff --git a/project/templates/customer/profile/license_list.html b/project/templates/customer/profile/license_list.html
index e973a67..01748f5 100644
--- a/project/templates/customer/profile/license_list.html
+++ b/project/templates/customer/profile/license_list.html
@@ -25,7 +25,7 @@
{{ license.pay_sum|get_plural:"рубль,рубля,рублей" }}
{{ license.get_payform_display }}
{{ license.get_status_display }}
- {{ license.get_action }}
+ {{ license.get_action_link|safe }}
{% if license.status == 0 %}
Удалить{% endif %}
diff --git a/project/templates/xls/4pd.xls b/project/templates/xls/4pd.xls
new file mode 100755
index 0000000..63f4d76
Binary files /dev/null and b/project/templates/xls/4pd.xls differ
diff --git a/project/templates/xls/act.xls b/project/templates/xls/act.xls
new file mode 100755
index 0000000..6adbff4
Binary files /dev/null and b/project/templates/xls/act.xls differ
diff --git a/project/templates/xls/bill.xls b/project/templates/xls/bill.xls
new file mode 100755
index 0000000..315dd7d
Binary files /dev/null and b/project/templates/xls/bill.xls differ
diff --git a/project/templates/xls/stamp.bmp b/project/templates/xls/stamp.bmp
new file mode 100755
index 0000000..096feb7
Binary files /dev/null and b/project/templates/xls/stamp.bmp differ
diff --git a/project/templates/xls/stamp1.bmp b/project/templates/xls/stamp1.bmp
new file mode 100755
index 0000000..c1bc52f
Binary files /dev/null and b/project/templates/xls/stamp1.bmp differ
diff --git a/requirements-dev.txt b/requirements-dev.txt
index 2372a19..7ece836 100644
--- a/requirements-dev.txt
+++ b/requirements-dev.txt
@@ -30,6 +30,7 @@ sqlparse==0.1.11
wsgiref==0.1.2
xlrd==0.9.2
xlwt==0.7.5
+xlutils==1.7.1
# dev
django-devserver
diff --git a/requirements.txt b/requirements.txt
index 916c679..f9349bb 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -30,5 +30,6 @@ sqlparse==0.1.11
wsgiref==0.1.2
xlrd==0.9.2
xlwt==0.7.5
+xlutils==1.7.1
flup