diff --git a/app/programs/calculo_quinta_peru/__init__.py b/app/programs/calculo_quinta_peru/__init__.py deleted file mode 100644 index 5d2f6ae..0000000 --- a/app/programs/calculo_quinta_peru/__init__.py +++ /dev/null @@ -1,12 +0,0 @@ -from manager import Manager - -from . import main - - -def exec(run_id): - with Manager(run_id) as _: - _.ensure_file_structure( - ignored_paths=[".DS_Store", "__MACOSX"], input_path="data" - ) - main.run(_) - _.output_dir = "results" diff --git a/app/programs/calculo_quinta_peru/main.py b/app/programs/calculo_quinta_peru/main.py deleted file mode 100644 index 8de54be..0000000 --- a/app/programs/calculo_quinta_peru/main.py +++ /dev/null @@ -1,28 +0,0 @@ -import sys -import time - -from status import Status - -from .modules import processor, reader, writer - - -def run(_): - start = time.time() - PROJECT = "Impuestos Quinta Perú" - VERSION = "V1.1" - _.log(f"Corriendo versión {VERSION}") - try: - base_pay = reader.read_base_pay(_=_) - total_pay = reader.read_total_pay(_=_) - variable_pay = processor.get_variable_pay(base_pay, total_pay) - taxes = processor.get_taxes(_, total_pay, base_pay, variable_pay) - header, formatted_taxes = processor.format_taxes(taxes) - writer.write_csv(_, header, formatted_taxes) - - except UnboundLocalError as err: - _.warning(f"No se encontró la página {err} en los archivos de ") - _.status = Status.CLIENT_ERROR - # except Exception as err: - # print(f"Ocurrio un error: {err}") - end = time.time() - _.log(f"Programa Finalizado en {round(end - start, 2)} segundos") diff --git a/app/programs/calculo_quinta_peru/modules/params.py b/app/programs/calculo_quinta_peru/modules/params.py deleted file mode 100644 index 7ee81de..0000000 --- a/app/programs/calculo_quinta_peru/modules/params.py +++ /dev/null @@ -1,8 +0,0 @@ -TAXES = [ - [[0, 22000], 0.08], - [[22000, 88000], 0.14], - [[88000, 154000], 0.17], - [[154000, 198000], 0.2], - [[198000, 99999999999], 0.3], -] -UIT = 4400 diff --git a/app/programs/calculo_quinta_peru/modules/paths.py b/app/programs/calculo_quinta_peru/modules/paths.py deleted file mode 100644 index e69de29..0000000 diff --git a/app/programs/calculo_quinta_peru/modules/processor.py b/app/programs/calculo_quinta_peru/modules/processor.py deleted file mode 100644 index 8748b8f..0000000 --- a/app/programs/calculo_quinta_peru/modules/processor.py +++ /dev/null @@ -1,98 +0,0 @@ -from bisect import bisect -from collections import namedtuple - -from status import Status - -from . import params - - -def get_variable_pay(base_pay, total_pay): # variable = total - base - VariablePay = namedtuple("VariablePay", ["dni", "name", "pay"]) - variable_pay = {} - for dni in base_pay: - pay = total_pay[dni].pay - base_pay[dni].pay - name = base_pay[dni].name - variable_pay[dni] = VariablePay(dni, name, pay) - return variable_pay - - -def get_taxes(_, total_pay, base_pay, variable_pay): # get taxes from brackets - Taxes = namedtuple( - "Taxes", - ["dni", "name", "pay", "base", "variable", "projection", "taxable", "tax"], - ) - taxes = {} - for dni in total_pay: - flag = True - try: - pay = total_pay[dni].pay - base = base_pay[dni].pay - variable = variable_pay[dni].pay - name = total_pay[dni].name - except KeyError: - _.warning(f"ALERTA: No esta presente algún dato para el DNI {dni}") - _.status = Status.WARNING - flag = False - if flag and pay > 2500: - base_projection = pay * 12 - # Add gratification of 2 months + 9% - grat_projection = pay * 2 - projection = base_projection + grat_projection + (grat_projection * 0.09) - taxable = projection - (7 * params.UIT) - total_tax = tax(taxable) / 12 # For given month - taxes[dni] = Taxes( - dni, name, pay, base, variable, projection, taxable, total_tax - ) - return taxes - - -def tax(income): - - rates = [8, 14, 17, 20, 30] # 10% 20% 30% - - brackets = [22000, 88000, 154000, 198000] # first 22,000 # next 66,000 - - base_tax = [1760, 11000, 22220, 31020] # Base tax for bracket - i = bisect(brackets, income) - if not i: - return (income * rates[0]) / 100 - rate = rates[i] - bracket = brackets[i - 1] - income_in_bracket = income - bracket - tax_in_bracket = income_in_bracket * rate / 100 - total_tax = base_tax[i - 1] + tax_in_bracket - return total_tax - - -def format_taxes(taxes): # Format for write function - header = [ - "DNI", - "Nombre y Apellido", - "Ingresos", - "Ingresos Fijos", - "Ingresos Variables", - "Proyección Ingresos", - "Ingreso Afecto", - "Impuesto (Mensual)", - ] - formatted = [] - for dni in taxes: - t = taxes[dni] - line = [ - dni, - t.name, - round(t.pay, 2), - round(t.base, 2), - round(t.variable, 2), - round(t.projection, 2), - round(t.taxable, 2), - round(t.tax, 2), - ] - formatted.append(line) - - return header, formatted - - -if __name__ == "__main__": - pass - # get_variable_pay() diff --git a/app/programs/calculo_quinta_peru/modules/reader.py b/app/programs/calculo_quinta_peru/modules/reader.py deleted file mode 100644 index ac13452..0000000 --- a/app/programs/calculo_quinta_peru/modules/reader.py +++ /dev/null @@ -1,67 +0,0 @@ -from collections import namedtuple - -from xlrd import open_workbook - -# from modules import paths - - -def read_base_pay(_, path="data/Datos Planilla Activos PB.xlsx"): # - _.log(f"Leyendo base pay...") - with open_workbook(_.get_path(path)) as wb: - for s in wb.sheets(): - base_pay = {} - BasePay = namedtuple("BasePay", ["dni", "name", "pay"]) - for row in range(2, s.nrows): - col_value = [s.cell(row, col).value for col in range(s.ncols)] - if row == 2: - header = col_value - dni_index = header.index("DNI Nº") - name_index = header.index("APELLIDOS Y NOMBRES") - base_pay_index = header.index("BASICO\nMENSUAL") - family_pay_index = header.index("ASIGN.\nFAMILIAR") - else: - dni = col_value[dni_index] - if dni: - dni = int(dni) - name = col_value[name_index] - base = col_value[base_pay_index] - family_pay = col_value[family_pay_index] - if not base: - base = 0 - else: - base = int(base) - if not family_pay: - family_pay = 0 - pay = base + family_pay - base_pay[dni] = BasePay(dni, name, pay) - return base_pay - - -def read_total_pay(_, path="data/Planilla Haberes Julio-2021 - Peru Brands.xlsx"): # - _.log(f"Leyendo total pay...") - with open_workbook(_.get_path(path)) as wb: - for s in wb.sheets(): - if s.name == "Planilla": - total_pay = {} - TotalPay = namedtuple("TotalPay", ["dni", "name", "pay"]) - for row in range(5, s.nrows): - col_value = [s.cell(row, col).value for col in range(s.ncols)] - if row == 5: - header = col_value - dni_index = header.index("DNI Nº") - name_index = header.index("APELLIDOS Y NOMBRES") - total_pay_index = header.index("TOTAL\nINGRESOS\nAFECTOS") - else: - dni = col_value[dni_index] - if dni: - dni = int(dni) - name = col_value[name_index] - pay = col_value[total_pay_index] - total_pay[dni] = TotalPay(dni, name, pay) - return total_pay - - -if __name__ == "__main__": - pass - read_base_pay() - read_total_pay() diff --git a/app/programs/calculo_quinta_peru/modules/writer.py b/app/programs/calculo_quinta_peru/modules/writer.py deleted file mode 100644 index 0288ab1..0000000 --- a/app/programs/calculo_quinta_peru/modules/writer.py +++ /dev/null @@ -1,38 +0,0 @@ -import xlsxwriter - - -def write_excel(_, header, data, name="test"): - # Create a workbook and add a worksheet. - path = f"results/{name}.xlsx" - _.makedirs(path) - workbook = xlsxwriter.Workbook(_.get_path(path)) - worksheet = workbook.add_worksheet() - # Start from the first cell. Rows and columns are zero indexed. - row = 0 - col = 0 - # write header - for pos in range(len(header)): - worksheet.write(row, pos, header[pos]) - row += 1 - # Iterate over the data and write it out row by row. - for line in data: - for col in range(len(line)): - worksheet.write(row, col, line[col]) - row += 1 - - workbook.close() - _.log(f"Se creó el archivo {name}.xlsx exitosamente") - - -def write_csv(_, header, data, name="test.csv"): - header = ", ".join(header) + "\n" - - path = f"results/{name}" - _.makedirs(path) - - with open(_.get_path(path), "w") as file: - file.write(header) - for line in data: - line = [str(x) for x in line] - file.write(", ".join(line) + "\n") - _.log(f"Se creó el archivo {name} exitosamente")