'''Created on 1 Feb 2023 @author: vnc-console''' # coding: UTF-8 import yagmail # noqa from jinja2 import Environment, PackageLoader import beautiful_date as bd # noqa from winmentor import WinMentor from .taxes import Taxes class M_mailer(object): date = (bd.D.today() - 1 * bd.months).strftime('%m_%Y') mentor_date = (bd.D.today() - 1 * bd.months - 5 * bd.days).strftime('%Y_%m') templates = Environment(loader=PackageLoader('winmentor', 'templates')) template = templates.get_template('body.html') @staticmethod def get_vat_period(vat_text): if vat_text == 'TVA-1': ret = 'Lunara' elif vat_text == 'TVA-2': ret = 'Trimestriala' else: ret = 'Neplatitor de TVA' return ret @staticmethod def get_tax_type(tax_text): if tax_text == 'IMP-1': ret = 'profit 16%' elif tax_text == 'IMP-21': ret = 'micro 1%' elif tax_text == 'IMP-23': ret = 'micro 3%' else: ret = '' return ret @staticmethod def due_date(): weekend = ['Saturday', 'Sunday'] d_date = (25 / bd.M[bd.D.today().month] / bd.D.today().year) if d_date.strftime('%A') in weekend: d_date = (25 / bd.M[bd.D.today().month] / bd.D.today().year) + bd.MO return d_date.strftime('%d-%m-%Y') @property def body(self): return self._body def tax_mailer(self, mentor_list: list, mail_dict: dict, mentor: WinMentor, yag: yagmail.SMTP, mentor_month: 'str'=None, send: bool=False) -> list[Taxes]: print(f'period should be "{M_mailer.date}"', end='\n' * 2) taxes = [] for company in mentor_list: for name, contact in mail_dict.items(): # print(company[10].split(sep=',')[1].split(sep=';')) condition = name == company[0] if condition: if mentor_month: if mentor_month >= mentor.get_last_month(company[6]): current_month = mentor.get_last_month(company[6]) else: current_month = mentor_month else: current_month = mentor.get_last_month(company[6]) print(current_month) if current_month == M_mailer.mentor_date: # print('True') account = mentor.verif_cont(company[6] + '/' + current_month + './NCONT.DB') print(f'...processing-->>{name}') vat = mentor.vat_payable(account) vat_final = mentor.vat_final(account) contrs = [mentor.CAS_payable(account), mentor.CASS_payable(account), mentor.sal_tax_payable(account)] contr = sum(contrs) cam = mentor.cam_payable(account) tax_payable = mentor.tax_payable(account) div_tax = mentor.div_tax_payable(account) other_tax = mentor.other_tax_payable(account) an_inc = mentor.an_inc(account, 0, 6, 8) result = mentor.result(account, 0, 6, 8) advance = mentor.advance_final(account) advance_previous = mentor.deb_div(account) cash_balance = mentor.cash_balance(account) vat_period = M_mailer.get_vat_period(company[10].split(sep=',')[0]) tax_type = M_mailer.get_tax_type(company[10].split(sep=',')[1].split(sep=';')[0]) data = {'name': name, 'date': M_mailer.date, 'vat': vat, 'vat_final': vat_final, 'contr': contr, 'cam': cam, 'tax_payable': tax_payable, 'div_tax': div_tax, 'other_tax': other_tax, 'an_inc': an_inc, 'result': result, 'advance': advance, 'advance_prev': advance_previous, 'cash_balance': cash_balance, 'tax_type': tax_type, 'vat_period': vat_period, 'due_date': M_mailer.due_date()} body = M_mailer.template.render(data) # print(body) self._body = body tax = Taxes(name=name, vat=vat, vat_final=vat_final, contribs=contr, cam=cam, income_tax=tax_payable, dividend_tax=div_tax, other_tax=other_tax, return_=an_inc, result=result, advance=advance, advance_previous=advance_previous, cash_balance=cash_balance, tax_type=tax_type, period=M_mailer.mentor_date) taxes.append(tax) if send: yag.send(to=contact['mail'], subject=f'Taxe {M_mailer.date}', contents=body) return taxes