Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from reportlab.lib.pagesizes import A4,landscape, portrait
- from reportlab.lib.units import mm
- from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
- from reportlab.lib.enums import TA_LEFT, TA_RIGHT, TA_CENTER, TA_JUSTIFY
- from reportlab.lib import colors
- from reportlab.pdfgen import *
- from reportlab.pdfgen.canvas import Canvas
- from reportlab.platypus import *
- from reportlab.platypus import Paragraph, Frame, Table, TableStyle, KeepInFrame, BaseDocTemplate, PageTemplate
- from reportlab.platypus import SimpleDocTemplate
- from reportlab.platypus import flowables
- from reportlab.platypus.paragraph import ParagraphStyle
- # from tkinter.font import *
- # font = Font(family= , size= , weight= , slant= , underline= , overstrike= )
- from reportlab.pdfbase.ttfonts import TTFont
- from reportlab.pdfbase import pdfmetrics
- from lib_data import data_table_a, list_style_a, data_table_p, text_antec, style_antec
- # Vertical elements size
- # -------------------------------------------
- styles = getSampleStyleSheet() #
- styleN = styles['BodyText']
- styleN.alignment = TA_LEFT
- styleBH = styles["Normal"]
- styleBH.alignment = TA_CENTER
- pdfmetrics.registerFont(TTFont('Times','Times.ttf', 'UTF-8'))
- pdfmetrics.registerFont(TTFont('Timesbd','Timesbd.ttf', 'UTF-8'))
- pdfmetrics.registerFont(TTFont('Timesi','Timesi.ttf', 'UTF-8'))
- pdfmetrics.registerFont(TTFont('Timesbi','Timesbi.ttf', 'UTF-8'))
- #pdfmetrics.registerFont(TTFont('Verdana', 'Verdana.ttf', 'UTF-8'))
- st = styles['Normal']
- styleTB = styles['BodyText']
- extra = []
- # -------------------------------------------
- def append_empty_row(empty_row, extra_row = None):
- if len_active > len_passive: # Добави diff_rows в пасива
- for i in range(1, diff_rows + 1):
- data_table_p2.append(['', '', ''])
- extra.append({'span': 'rows', "bgcolor": "gray"})
- elif len_active < len_passive: # Добави diff_rows в актива
- for i in range(1, diff_rows + 1):
- data_table_a2.append(['', '', ''])
- extra.append({'span': 'rows', "bgcolor": "gray"})
- else:
- return
- def margins(): # Line coordinates
- balance_3.setLineWidth(0.01) # Дебелина на линията
- balance_3.setStrokeColor('greenyellow') # Цвят на линията
- balance_3.line(left_m, bottom_m, left_m, A4[1] - top_m) # Left margin
- balance_3.line(left_m, A4[1] - top_m, A4[0] - right_m, A4[1] - top_m) # Top margin
- balance_3.line(A4[0] - right_m, A4[1] - top_m, A4[0] - right_m, bottom_m) # Right margin
- balance_3.line(A4[0] - right_m, bottom_m, left_m, bottom_m) # Bottom margin
- balance_3.setStrokeColor('red') # Цвят на линията
- def frames(x0, y0, width, height, bound, id, story=None):
- if story is None:
- story = []
- frame = Frame(x0, y0, width, height, showBoundary=bound, bottomPadding=0,
- topPadding=0, leftPadding=0, rightPadding=0)
- frame.addFromList(story, balance_3) # Показва frame
- return frame
- top_m = 25*mm #
- top_f = A4[1] * 0.1
- bottom_f_h = A4[1] * 0.1
- end_f_h = A4[1] * 0.122
- bottom_m = 25*mm #
- balance_f = A4[1] - top_m - top_f - bottom_f_h - end_f_h - bottom_m
- # Horizontal elements size
- left_m = 25*mm # 25mm / 210mm = 0.119
- right_m = 25*mm
- w_antec = A4[0] - left_m - right_m # Широчина на антетката 453.54330708661416
- h_antec = 5 * 5 * mm
- col_0 = col_3 = w_antec / 2 - 29 - 29 # 337.54330708661416 337.54330708661416
- print(w_antec)
- print(col_0, col_3)
- h_active = (A4[1] - top_m - top_f - h_antec - bottom_f_h - end_f_h - bottom_m) # h_Aктива
- w_active = w_passive = w_antec / 2 #A4[0] * 0.38
- top_f_l_width = (w_antec) / 3
- # Top_frame_right + coordinates
- top_f_r_width = top_f_l_width
- # Bottom_frame_left
- bottom_f_l = top_f_r_width
- # Bottom_frame_right
- bottom_f_r = top_f_r_width
- # End_frame
- end_f_w = (w_antec) * 0.6
- balance_3 = Canvas('Balance_3.pdf', pagesize=A4) # Balance_3.pdf
- # Margins
- margins()
- # Top frame left
- story = []
- story.append(Paragraph('"<font face=Timesbd>ОФИС ГЕОРГИЕВ ЕООД</font>"'))
- story.append(Paragraph('<font face=Times>4230 Асеновград, ул. "Княз Александър Батенберг", № 24</font>'))
- story.append(Paragraph('<br/><br/><font face=Times>Дата на съставяне:</font> <font face=Timesbd>19.06.2022 г.</font>'))
- frames(left_m, A4[1] - top_m - top_f, top_f_l_width, top_f, 0, 'top_frame_left', story)
- # Top frame right
- story = []
- story.append(Paragraph('<font face=Timesbd>ПРИЛОЖЕНИЕ</font><font face=Times> 1 към НСС 1</font>'))
- story.append(Paragraph('<font face=Timesbd>ЕИК:</font><font face=Times> 825 613 327</font>'))
- story.append(Paragraph('<font face=Timesbd>КИД:</font><font face=Times> 4120</font>'))
- story.append(Paragraph('<font face=Timesbd>Наименование:</font><font face=Times> Строителство на жилищни'
- ' и нежилищни сгради</font>'))
- frames(A4[0] - right_m - top_f_r_width, A4[1] - top_m - top_f, top_f_r_width, top_f, 0, 'top_frame_right', story)
- title = 'СЧЕТОВОДЕН БАЛАНС'
- pdfmetrics.registerFont((TTFont('Timesbd', 'timesbd.ttf')))
- text_len = balance_3.stringWidth(title, "Timesbd", 9)
- balance_3.setFont('Timesbd', 9, leading=100)
- balance_3.drawString(left_m + w_active - text_len / 2, A4[1] - top_m - top_f + 20, title)
- # print(text_len)
- data_balance = 'към 31.12.2021г.'
- pdfmetrics.registerFont((TTFont('Times', 'times.ttf')))
- text_len = balance_3.stringWidth(data_balance, "Times", 9) # Дава широчината на стринга
- balance_3.setFont('Times', 9, leading=100)
- balance_3.drawString(left_m + w_active - text_len / 2, A4[1] - top_m - top_f + 8, data_balance)
- # АНТЕТКА
- # Антетка - Таблица
- t_antec = Table(
- text_antec,
- colWidths=[col_0, 29, 29, col_3, 29, 29], # 234.13779527559058
- rowHeights=5*mm
- )
- # Story Антетка
- story_antec = []
- t_antec.setStyle(style_antec)
- story_antec.append(t_antec)
- # Антетка - Frame
- x1 = left_m # x начало на Balance_frame_left
- y1 = A4[1] - top_m - top_f - h_antec # y начало на Balance_frame_left
- frames(x1, y1, w_antec, h_antec, 1, 'antec_frame', story_antec)
- # ДЪЛЖИНА НА БАЛАНСА
- max_num_data_rows = 45
- # Активи
- num_dat_rows = len(data_table_a)
- data_table_a1 = data_table_a
- odit = True
- # if odit:
- # if total_rows > 39:
- # sheet_2 = True
- data_table_a2 = [] # Таблица за страница 2
- if num_dat_rows > max_num_data_rows:
- data_table_a1 = data_table_a[0: max_num_data_rows - 1] # от 0 до 44 = общо 45
- data_table_a2 = data_table_a[max_num_data_rows:] # от 45 до края
- # Пасиви
- num_dat_rows_p = len(data_table_p)
- data_table_p1 = data_table_p
- data_table_p2 = [] # Таблица за страница 2
- if num_dat_rows_p > max_num_data_rows:
- data_table_p1 = data_table_p[0: max_num_data_rows - 1] # от 0 до 44 = общо 45
- data_table_p2 = data_table_p[max_num_data_rows:] # от 45 до края
- # БАЛАНС АКТИВИ
- ta = Table(
- data_table_a1,
- colWidths=[(w_active - 58), 29, 29], # 234.13779527559058
- rowHeights=4*mm,
- )
- w, h = ta.wrap(0, 0) # Дава размерите на таблицата
- # print(w, ' ', h) # 240.94488188976382 419.52755905511816
- story_a = []
- ta.setStyle(list_style_a)
- story_a.append(ta)
- # ----------------------------------------
- # Брой редове в таблицата на Balance_frame_left
- count_data_rows = len(data_table_a)
- # print(count_data_rows) # 37
- # Balance frame left
- x1 = left_m # x начало на Balance_frame_left
- y1 = A4[1] - top_m - top_f - h_antec - h # y начало на Balance_frame_left
- balance_frame_left_height = h
- frames(x1, y1, w_active, balance_frame_left_height, 1, 'balance_frame_left', story_a)
- # БАЛАНС ПАСИВИ
- tp = Table(
- data_table_p1,
- colWidths=[(w_passive - 58), 29, 29], # 234.13779527559058
- rowHeights=4*mm,
- )
- w_p, h_p = ta.wrap(0, 0) # Дава размерите на таблицата
- # print(w_p, ' ', h_p) # 240.94488188976382 419.52755905511816
- story_p = []
- tp.setStyle(list_style_a)
- story_p.append(tp)
- # ----------------------------------------
- # Брой редове в таблицата на Balance_frame_passive
- count_data_rows_p = len(data_table_p)
- # print(count_data_rows) # 37
- # Balance frame passive
- x1_r_f = left_m + w_passive
- balance_frame_right_height = h_p
- frames(x1_r_f, y1, w_passive, balance_frame_right_height, 1, 'balance_frame_right', story_p)
- if count_data_rows > 45:
- page_num = balance_3.getPageNumber()
- end_page = 'Страница 1 от 2'
- pdfmetrics.registerFont((TTFont('Timesbs', 'timesbi.ttf')))
- text_len = balance_3.stringWidth(end_page, "Timesbi", 10)
- balance_3.setFont('Timesbi', 9, leading=100)
- balance_3.drawString(left_m + w_active - text_len / 2, y1 - 40, f'Страница {page_num} от 2')
- balance_3.showPage()
- margins()
- # ------------------------------------------------
- pdfmetrics.registerFont(TTFont('Times', 'Times.ttf', 'UTF-8'))
- pdfmetrics.registerFont(TTFont('Timesbd', 'Timesbd.ttf', 'UTF-8'))
- pdfmetrics.registerFont(TTFont('Timesi', 'Timesi.ttf', 'UTF-8'))
- pdfmetrics.registerFont(TTFont('Timesbi', 'Timesbi.ttf', 'UTF-8'))
- # pdfmetrics.registerFont(TTFont('Verdana', 'Verdana.ttf', 'UTF-8'))
- st = styles['Normal']
- # ------------------------------------------------
- # Top frame left
- story = []
- story.append(Paragraph('"<font face=Timesbd>ОФИС ГЕОРГИЕВ ЕООД</font>"'))
- story.append(Paragraph('<font face=Times>4230 Асеновград, ул. "Княз Александър Батенберг", № 24</font>'))
- story.append(
- Paragraph('<br/><br/><font face=Times>Дата на съставяне:</font> <font face=Timesbd>19.06.2022 г.</font>'))
- frames(left_m, A4[1] - top_m - top_f, top_f_l_width, top_f, 0, 'top_frame_left', story)
- # Top frame right
- story = []
- story.append(Paragraph('<font face=Timesbd>ПРИЛОЖЕНИЕ</font><font face=Times> 1 към НСС 1</font>'))
- story.append(Paragraph('<font face=Timesbd>ЕИК:</font><font face=Times> 825 613 327</font>'))
- story.append(Paragraph('<font face=Timesbd>КИД:</font><font face=Times> 4120</font>'))
- story.append(Paragraph(
- '<font face=Timesbd>Наименование:</font><font face=Times> Строителство на жилищни и нежилищни сгради</font>'))
- frames(A4[0] - right_m - top_f_r_width, A4[1] - top_m - top_f, top_f_r_width, top_f, 0, 'top_frame_right', story)
- title = 'СЧЕТОВОДЕН БАЛАНС'
- pdfmetrics.registerFont((TTFont('Timesbd', 'timesbd.ttf')))
- text_len = balance_3.stringWidth(title, "Timesbd", 9)
- balance_3.setFont('Timesbd', 9, leading=100)
- balance_3.drawString(left_m + w_active - text_len / 2, A4[1] - top_m - top_f + 20, title)
- # print(text_len)
- data_balance = 'към 31.12.2021г.'
- pdfmetrics.registerFont((TTFont('Times', 'times.ttf')))
- text_len = balance_3.stringWidth(data_balance, "Times", 9) # Дава широчината на стринга
- balance_3.setFont('Times', 9, leading=100)
- balance_3.drawString(left_m + w_active - text_len / 2, A4[1] - top_m - top_f + 8, data_balance)
- # АНТЕТКА 2
- # Антетка - Таблица
- t_antec_2 = Table(
- text_antec,
- colWidths=[col_0, 29, 29, col_3, 29, 29], # 234.13779527559058
- rowHeights=5 * mm
- )
- # Story Антетка
- story_antec = []
- t_antec_2.setStyle(style_antec)
- story_antec.append(t_antec_2)
- # Антетка - Frame
- x1 = left_m # x начало на Balance_frame_left
- y1 = A4[1] - top_m - top_f - h_antec # y начало на Balance_frame_left
- frames(x1, y1, w_antec, h_antec, 1, 'antec_frame', story_antec)
- # Таблица Актив стр. 2
- ta2 = Table(
- data_table_a2,
- colWidths=[(w_active - 58), 29, 29], # 234.13779527559058
- rowHeights=4 * mm,
- )
- w, h = ta2.wrap(0, 0) # Дава размерите на таблицата
- # print(w, ' ', h) # 240.94488188976382 419.52755905511816
- story_a_2 = []
- ta2.setStyle(list_style_a)
- story_a_2.append(ta2)
- # Balance frame left
- x1 = left_m # x начало на Balance_frame_left
- y1 = A4[1] - top_m - top_f - h_antec - h # y начало на Balance_frame_left
- balance_frame_left_height = h
- frames(x1, y1, w_active, balance_frame_left_height, 1, 'balance_frame_left_2', story_a_2)
- # Таблица Пасив стр. 2
- tp2 = Table(
- data_table_p2,
- colWidths=[(w_passive - 58), 29, 29], # 234.13779527559058
- rowHeights= 4 * mm
- )
- w_p, h_p = tp2.wrap(0, 0) # Дава размерите на таблицата
- # print(w_p, ' ', h_p) # 240.94488188976382 419.52755905511816
- story_p_2 = []
- tp2.setStyle(list_style_a)
- story_p_2.append(tp2)
- # Balance frame passive
- # x1 = left_m # x начало на Balance_frame_left
- y1_p = A4[1] - top_m - top_f - h_antec - h_p # y начало на Balance_frame_right
- balance_frame_right_height = h_p
- frames(x1_r_f, y1_p, w_passive, balance_frame_right_height, 1, 'balance_frame_passive_2', story_p_2)
- len_active = len(data_table_a2)
- len_passive = len(data_table_p2)
- diff_rows = abs(len_active - len_passive)
- print(len_active)
- print(len_passive)
- if len_active > len_passive:
- print('Добави diff_rows в пасива')
- elif len_active < len_passive:
- print('Добави diff_rows в актива')
- if len_active > len_passive:
- y1 = A4[1] - top_m - top_f - h_antec - balance_frame_left_height - bottom_f_h - 10 * mm
- else:
- y1 = A4[1] - top_m - top_f - h_antec - h_p - bottom_f_h - 10 * mm
- # Изравнява Актива и Пасива
- append_empty_row()
- # Bottom frame left
- story = []
- story.append(Paragraph('<font face=Timesbd>Ръководител: .......................</font>'))
- story.append(Paragraph('<font face=Times>АЛЕКСАНДЪР ГЕОРГИЕВ ГЕОРГИЕВ</font>'))
- #y1 = A4[1] - top_m - top_f - h_antec - balance_frame_left_height - bottom_f_h - 10 * mm
- frames(x1, y1, w_active, bottom_f_h, 0, 'bottom_frame_left', story)
- # # Bottom frame right
- story = []
- story.append(Paragraph('<font face=Timesbd>Съставител: .......................</font>'))
- story.append(Paragraph('<font face=Times>СП "ОФИС ГЕОРГИЕВ ЕООД"</font>'))
- story.append(Paragraph('<font face=Times>4230 Асеновград, ул."Цар Иван Асен II, № 47"</font>'))
- story.append(Paragraph('<font face=Times>ЕИК: 115 882 107</font>'))
- story.append(Paragraph('<font face=Timesbd>Представляващ: .......................</font>'))
- story.append(Paragraph('<font face=Times>АЛЕКСАНДЪР ГЕОРГИЕВ ГЕОРГИЕВ</font>'))
- x1 = left_m + w_active
- frames(x1, y1, w_passive, bottom_f_h, 0, 'bottom_frame_right', story)
- # Записки на одитора end_frame
- story = []
- story.append(Paragraph('<font face=Times>Годишният финансов отчет е одобрен (утвърден) и подписан от ръководството'
- ' с протокол на съвета на директорите от 24.06.2022 година.</font>'))
- story.append(Paragraph('<font face=Times>Пояснителните бележки изложени в Приложението от стр. 1 до стр. 21, са'
- ' неразделна част от този годишен финансов отчет."</font>'))
- story.append(Paragraph('<font face=Times>Заверил съгласно одиторски доклад с немодифицирано (неквалифицирано)'
- ' мнение с § за внимание, издаден на 2.04.2022 година."</font>'))
- story.append(Paragraph('<font face=Times>Регистриран одитор: 0423 Костадин Арнаудов</font>'))
- # # End frame
- frames(left_m, bottom_m + 70, w_antec, end_f_h, 1, 'bottom_frame_right', story)
- # Страница 2 от 2
- page_num = balance_3.getPageNumber()
- end_page = 'Страница 1 от 2'
- pdfmetrics.registerFont((TTFont('Timesbs', 'timesbi.ttf')))
- text_len = balance_3.stringWidth(end_page, "Timesbi", 10)
- balance_3.setFont('Timesbi', 9, leading=100)
- balance_3.drawString(left_m + w_antec / 2 - text_len / 2, bottom_m + 50, f'Страница {page_num} от 2')
- else:
- #Bottom frame left
- story = []
- story.append(Paragraph('<font face=Timesbd>Ръководител: .......................</font>'))
- story.append(Paragraph('<font face=Times>АЛЕКСАНДЪР ГЕОРГИЕВ ГЕОРГИЕВ</font>'))
- y1 = A4[1] - top_m - top_f - balance_frame_left_height - bottom_f_h - 10 * mm
- frames(x1, y1, w_active, bottom_f_h, 0, 'bottom_frame_left', story)
- # # Bottom frame right
- story = []
- story.append(Paragraph('<font face=Timesbd>Съставител: .......................</font>'))
- story.append(Paragraph('<font face=Times>СП "ОФИС ГЕОРГИЕВ ЕООД"</font>'))
- story.append(Paragraph('<font face=Times>4230 Асеновград, ул."Цар Иван Асен II, № 47"</font>'))
- story.append(Paragraph('<font face=Times>ЕИК: 115 882 107</font>'))
- story.append(Paragraph('<font face=Timesbd>Представляващ: .......................</font>'))
- story.append(Paragraph('<font face=Times>АЛЕКСАНДЪР ГЕОРГИЕВ ГЕОРГИЕВ</font>'))
- x1_b_f_r, y1_b_f_r = left_m + w_active, A4[1] - top_m - top_f - balance_f - bottom_f_h
- frames(x1_b_f_r, y1, w_passive, bottom_f_h, 0, 'bottom_frame_right', story)
- balance_3.showPage() # saves current page
- balance_3.save() # stores the file and close the canvas
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement