tax_mailer.py 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. '''Created on 1 Feb 2023 @author: vnc-console'''
  2. # coding: UTF-8
  3. import yagmail # noqa
  4. from jinja2 import Environment, PackageLoader
  5. import beautiful_date as bd # noqa
  6. from winmentor import WinMentor
  7. from .taxes import Taxes
  8. class M_mailer(object):
  9. date = (bd.D.today() - 1 * bd.months).strftime('%m_%Y')
  10. mentor_date = (bd.D.today() - 1 * bd.months - 5 * bd.days).strftime('%Y_%m')
  11. templates = Environment(loader=PackageLoader('winmentor', 'templates'))
  12. template = templates.get_template('body.html')
  13. @staticmethod
  14. def get_vat_period(vat_text):
  15. if vat_text == 'TVA-1':
  16. ret = 'Lunara'
  17. elif vat_text == 'TVA-2':
  18. ret = 'Trimestriala'
  19. else:
  20. ret = 'Neplatitor de TVA'
  21. return ret
  22. @staticmethod
  23. def get_tax_type(tax_text):
  24. if tax_text == 'IMP-1':
  25. ret = 'profit 16%'
  26. elif tax_text == 'IMP-21':
  27. ret = 'micro 1%'
  28. elif tax_text == 'IMP-23':
  29. ret = 'micro 3%'
  30. else:
  31. ret = ''
  32. return ret
  33. @staticmethod
  34. def due_date():
  35. weekend = ['Saturday', 'Sunday']
  36. d_date = (25 / bd.M[bd.D.today().month] / bd.D.today().year)
  37. if d_date.strftime('%A') in weekend:
  38. d_date = (25 / bd.M[bd.D.today().month] / bd.D.today().year) + bd.MO
  39. return d_date.strftime('%d-%m-%Y')
  40. @property
  41. def body(self):
  42. return self._body
  43. def tax_mailer(self, mentor_list: list,
  44. mail_dict: dict,
  45. mentor: WinMentor,
  46. yag: yagmail.SMTP,
  47. mentor_month: 'str'=None,
  48. send: bool=False) -> list[Taxes]:
  49. print(f'period should be "{M_mailer.date}"', end='\n' * 2)
  50. taxes = []
  51. for company in mentor_list:
  52. for name, contact in mail_dict.items():
  53. # print(company[10].split(sep=',')[1].split(sep=';'))
  54. condition = name == company[0]
  55. if condition:
  56. if mentor_month:
  57. if mentor_month >= mentor.get_last_month(company[6]):
  58. current_month = mentor.get_last_month(company[6])
  59. else:
  60. current_month = mentor_month
  61. else:
  62. current_month = mentor.get_last_month(company[6])
  63. print(current_month)
  64. if current_month == M_mailer.mentor_date:
  65. # print('True')
  66. account = mentor.verif_cont(company[6] + '/' + current_month + './NCONT.DB')
  67. print(f'...processing-->>{name}')
  68. vat = mentor.vat_payable(account)
  69. vat_final = mentor.vat_final(account)
  70. contrs = [mentor.CAS_payable(account),
  71. mentor.CASS_payable(account),
  72. mentor.sal_tax_payable(account)]
  73. contr = sum(contrs)
  74. cam = mentor.cam_payable(account)
  75. tax_payable = mentor.tax_payable(account)
  76. div_tax = mentor.div_tax_payable(account)
  77. other_tax = mentor.other_tax_payable(account)
  78. an_inc = mentor.an_inc(account, 0, 6, 8)
  79. result = mentor.result(account, 0, 6, 8)
  80. advance = mentor.advance_final(account)
  81. advance_previous = mentor.deb_div(account)
  82. cash_balance = mentor.cash_balance(account)
  83. vat_period = M_mailer.get_vat_period(company[10].split(sep=',')[0])
  84. tax_type = M_mailer.get_tax_type(company[10].split(sep=',')[1].split(sep=';')[0])
  85. data = {'name': name,
  86. 'date': M_mailer.date,
  87. 'vat': vat,
  88. 'vat_final': vat_final,
  89. 'contr': contr,
  90. 'cam': cam,
  91. 'tax_payable': tax_payable,
  92. 'div_tax': div_tax,
  93. 'other_tax': other_tax,
  94. 'an_inc': an_inc,
  95. 'result': result,
  96. 'advance': advance,
  97. 'advance_prev': advance_previous,
  98. 'cash_balance': cash_balance,
  99. 'tax_type': tax_type,
  100. 'vat_period': vat_period,
  101. 'due_date': M_mailer.due_date()}
  102. body = M_mailer.template.render(data)
  103. # print(body)
  104. self._body = body
  105. tax = Taxes(name=name, vat=vat, vat_final=vat_final, contribs=contr,
  106. cam=cam, income_tax=tax_payable, dividend_tax=div_tax, other_tax=other_tax,
  107. return_=an_inc, result=result, advance=advance, advance_previous=advance_previous, cash_balance=cash_balance, tax_type=tax_type, period=M_mailer.mentor_date)
  108. taxes.append(tax)
  109. if send:
  110. yag.send(to=contact['mail'], subject=f'Taxe {M_mailer.date}', contents=body)
  111. return taxes