parent
cad014d17c
commit
b7f6244b34
14 changed files with 117 additions and 116 deletions
|
After Width: | Height: | Size: 8.4 KiB |
|
After Width: | Height: | Size: 8.4 KiB |
|
After Width: | Height: | Size: 79 KiB |
@ -1,109 +1,87 @@ |
|||||||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||||||
import os |
|
||||||
import re |
|
||||||
|
|
||||||
from django.conf import settings |
from django.conf import settings |
||||||
from django.http import Http404, HttpResponseForbidden, HttpResponse |
from django.http import HttpResponseForbidden, HttpResponse |
||||||
|
|
||||||
from xlwt import easyxf |
|
||||||
from xlrd import open_workbook |
|
||||||
from xlutils.copy import copy |
|
||||||
from pytils.numeral import rubles |
|
||||||
|
|
||||||
|
from commons.pdf_tools import render_pdf_to_string |
||||||
from customer.models import License |
from customer.models import License |
||||||
from customer.utils import raise_if_no_profile |
from customer.utils import raise_if_no_profile |
||||||
|
|
||||||
|
|
||||||
XLS_ROOT = os.path.join(settings.TEMPLATES[0]['DIRS'][0], 'xls') |
def create_payment_account(request, order_num=None): |
||||||
|
|
||||||
|
|
||||||
def get_doc(request, order_num=None): |
|
||||||
if not request.user.is_authenticated(): |
if not request.user.is_authenticated(): |
||||||
raise HttpResponseForbidden |
raise HttpResponseForbidden |
||||||
|
|
||||||
raise_if_no_profile(request) |
raise_if_no_profile(request) |
||||||
|
|
||||||
license = License.objects.get(pk=order_num) |
lic = License.objects.get(pk=order_num) |
||||||
pm = license.payform |
pay_form = lic.payform |
||||||
data = request.user.profile |
customer = request.user.profile |
||||||
if pm == 0: |
|
||||||
tmp_name = 'bill.xls' |
response = HttpResponse(content_type='application/pdf') |
||||||
file_name = f"Invoice No.{order_num}.xls" |
|
||||||
elif pm == 2: |
profile = { |
||||||
tmp_name = '4pd.xls' |
'is_org': True, |
||||||
file_name = f"Kvitanciya na oplatu zakaza No.{order_num}.xls" |
'get_company_name': settings.OWNER['NAME'], |
||||||
else: |
'address': settings.OWNER['ADDRESS'], |
||||||
raise Http404() |
'phone': settings.OWNER['PHONE'], |
||||||
|
'get_full_phone': settings.OWNER['PHONE'], |
||||||
response = HttpResponse(content_type="application/vnd.ms-excel") |
'inn': settings.OWNER['INN'], |
||||||
response['Content-Disposition'] = f'attachment; filename={file_name}' |
'kpp': settings.OWNER['KPP'], |
||||||
|
'get_boss_fio': settings.OWNER['BOSS'], |
||||||
rb = open_workbook(os.path.join(XLS_ROOT, tmp_name), on_demand=True, formatting_info=True) |
'get_boss_title': settings.OWNER['POSITION_BOSS'], |
||||||
wb = copy(rb) |
'get_glavbuh_fio': settings.OWNER['GB'], |
||||||
ws = wb.get_sheet(0) |
'boss_sign': { |
||||||
|
'path': settings.OWNER['SIGN_BOSS'] |
||||||
# отключить колонтитулы |
}, |
||||||
ws.show_headers = 0 |
'glavbuh_sign': { |
||||||
ws.print_headers = 0 |
'path': settings.OWNER['SIGN_GB'] |
||||||
ws.header_str = b'' |
}, |
||||||
ws.footer_str = b'' |
'stamp': { |
||||||
|
'path': settings.OWNER['STAMP'] |
||||||
# заполняем счет |
} |
||||||
if pm == 0: |
} |
||||||
style0 = easyxf('font: name Times New Roman, height 280, bold True;') |
|
||||||
style0_center = \ |
if pay_form == 0: |
||||||
easyxf('font: name Times New Roman, height 280, bold True; align: horiz center') |
response['Content-Disposition'] = \ |
||||||
style1 = easyxf('font: name Times New Roman, height 180;') |
f'attachment; filename="Schet_{order_num}_Dokumentor-ru.pdf"' |
||||||
style2 = easyxf('font: name Times New Roman, height 180, bold True;') |
|
||||||
style3 = easyxf('font: name Times New Roman, height 180;' |
obj = { |
||||||
'border: top thin, left thin, right thin, bottom thin;' |
'bank_account': { |
||||||
) |
'name': settings.OWNER['BANK'], |
||||||
style4 = easyxf('font: name Times New Roman, height 180, bold True;' |
'account': settings.OWNER['BANK_ACC'], |
||||||
'border: top thin, left thin, right thin, bottom thin;' |
'korr_account': settings.OWNER['CORR_ACC'], |
||||||
) |
'bik': settings.OWNER['BIK'] |
||||||
style4.num_format_str = "#,##0.00" |
}, |
||||||
|
'client': { |
||||||
ws.write(11, 0, f"СЧЕТ № {order_num} от {license.order_date.strftime('%d.%m.%Y')}", |
'name': customer.get_company_name(), |
||||||
style0_center) |
'get_inn_and_kpp': customer.get_inn_and_kpp(), |
||||||
ws.write(13, 0, f"Покупатель: {data.name}", style1) |
'address': customer.address, |
||||||
ws.write(16, 2, f"Лицензия Dokumentor.ru на {license.get_term()}", style3) |
'contact_phone': customer.get_full_phone() |
||||||
|
}, |
||||||
style3.num_format_str = "#,##0.00" |
'doc_num': order_num, |
||||||
|
'doc_date': lic.order_date, |
||||||
ws.write(16, 36, license.pay_sum, style3) |
'total_price': lic.pay_sum, |
||||||
ws.write(16, 44, license.pay_sum, style3) |
'sum_total_nds': 0, |
||||||
ws.write(17, 44, license.pay_sum, style4) |
'nds_itogo_text': 'Без налога (НДС)', |
||||||
ws.write(19, 44, license.pay_sum, style4) |
'sum_total_price': lic.pay_sum, |
||||||
ws.write(21, 0, f"Всего наименование 1, на сумму {license.pay_sum},00 руб.", style1) |
'sum_full_total_price': lic.pay_sum |
||||||
ws.write(23, 0, f"{rubles(license.pay_sum).capitalize()}.", style2) |
} |
||||||
|
|
||||||
ws.insert_bitmap(os.path.join(XLS_ROOT, 'stamp.bmp'), 26, 12, y=3, scale_y=1.1) |
obj_items = [{ |
||||||
|
'name': f'Лицензия на ПО Dokumentor на {lic.get_term()}', |
||||||
# заполняем квитанцию |
'units': 'услуги', |
||||||
elif pm == 2: |
'qty': 1, |
||||||
style0 = easyxf('font: name Times New Roman, height 160, bold True;' |
'price': lic.pay_sum, |
||||||
'border: bottom thin;' |
'total_price': lic.pay_sum |
||||||
) |
}] |
||||||
style1 = easyxf('font: name Times New Roman, height 160, bold True;' |
|
||||||
'border: bottom thin;' |
dictionary = { |
||||||
'align: horiz center;' |
'obj': obj, |
||||||
) |
'doc_sign': True, |
||||||
|
'obj_items': obj_items, |
||||||
# заполняем оригинал |
'profile': profile, |
||||||
ws.write(11, 4, f"Лицензия Dokumentor.ru на {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) |
pdf = render_pdf_to_string(request, 'docs/invoice/as_pdf.html', dictionary) |
||||||
ws.write(15, 11, license.pay_sum, style1) |
response.write(pdf) |
||||||
|
return response |
||||||
# заполняем копию |
|
||||||
ws.write(31, 4, u"Лицензия Dokumentor.ru на %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 |
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 106 KiB |
|
Before Width: | Height: | Size: 103 KiB |
Loading…
Reference in new issue