Advertisement
ALEXANDAR_GEORGIEV

acc_rec_calculations

Jan 4th, 2023
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 9.20 KB | Source Code | 0 0
  1. from json_file_io import JsonFileIo
  2. from Opiti.from_excel.classes.global_inc import registry
  3. from cells_table import Cells
  4. from mapped_acc_calculations import *
  5.  
  6.  
  7. class AccRecCalculations:
  8.     def __init__(self):
  9.         self.acc_rec_da = self.get_acc_rec_da_init_values()
  10.         self.exact = Cells()
  11.         self.round1000 = Cells()
  12.  
  13.         try:
  14.             json_file_io = JsonFileIo(file_name=registry["acc_rec_da_file_name"])
  15.             tmp_acc_rec_da = json_file_io.read_content()
  16.             if tmp_acc_rec_da is not None:
  17.                 self.acc_rec_da = tmp_acc_rec_da
  18.         except:
  19.             pass
  20.  
  21.         mapped_calculations = MappedCalculations()
  22.  
  23.         da_keys = {
  24.              4: "prd",  5: "pp",  6: "tr",  7: "rpna",  8: "adv",
  25.             11: "pdr", 12:  "z", 13: "pz", 14:    "s", 15: "m",
  26.             16: "sdr", 17: "ts", 18: "rpma", 19: "advm",
  27.             22: "adp", 23: "pzp", 24: "adas", 25: "pzas", 26: "di", 27:"drz", 28: "isa", 30: "ltax"
  28.         }
  29.  
  30.         for r_idx, da_key in da_keys.items():
  31.             debug_rows = [5]
  32.             assets = mapped_calculations.sum_by_accs(self.acc_rec_da[da_key]["assets"])  # 6 суми в лв.ст
  33.             amort = mapped_calculations.sum_by_accs(self.acc_rec_da[da_key]["amort"])  # 6 суми в лв.ст
  34.             if r_idx in debug_rows:
  35.                 print(f"r_idx {r_idx} self.acc_rec_da[{da_key}] {self.acc_rec_da[da_key]}")
  36.             self.exact.setItem(r_idx, 1, self.acc_rec_da[da_key]["ns"] * 1000)
  37.             self.exact.setItem(r_idx, 2, assets["td"])
  38.             self.exact.setItem(r_idx, 3, assets["tc"])
  39.             self.exact.setItem(r_idx, 4, assets["cd"])
  40.             if r_idx in [7, 8, 18, 19]:
  41.                 pass
  42.             else:
  43.                 self.exact.setItem(r_idx, 5, self.acc_rec_da[da_key]["assets_re"]["inc"])
  44.                 self.exact.setItem(r_idx, 6, self.acc_rec_da[da_key]["assets_re"]["dec"])
  45.             self.exact.setItem(r_idx, 7, self.exact.getNumber(r_idx, 4) + self.exact.getNumber(r_idx, 5) - self.exact.getNumber(r_idx, 6))
  46.             if r_idx in [7, 8, 12, 18, 19, 22, 23, 24, 25, 27, 28, 30]:
  47.                 pass
  48.             else:
  49.                 self.exact.setItem(r_idx, 8, self.acc_rec_da[da_key]["ns_amo"] * 1000)
  50.                 self.exact.setItem(r_idx, 9, amort["tc"])
  51.                 self.exact.setItem(r_idx, 10, amort["td"])
  52.                 self.exact.setItem(r_idx, 11, amort["cc"])
  53.                 self.exact.setItem(r_idx, 12, self.acc_rec_da[da_key]["amort_re"]["inc"])
  54.                 self.exact.setItem(r_idx, 13, self.acc_rec_da[da_key]["amort_re"]["dec"])
  55.                 self.exact.setItem(r_idx, 14, self.exact.getNumber(r_idx, 11) + self.exact.getNumber(r_idx, 12) - self.exact.getNumber(r_idx, 13))
  56.             self.exact.setItem(r_idx, 15, self.exact.getNumber(r_idx, 7) - self.exact.getNumber(r_idx, 14))     # TODO -> k.15 е най-вярно закръглена !!!!
  57.             for c in range(1, 16):
  58.                 exactItem = self.exact.getItem(r_idx, c)
  59.                 if isinstance(exactItem, float) or isinstance(exactItem, int):
  60.                     self.round1000.setItem(r_idx, c, round(self.exact.getNumber(r_idx, c) / 1000))
  61.         for c_idx in range(1, 15+1):
  62.             if self.exact.getItem(4, c_idx) is not None:
  63.                 self.exact.setItem(9, c_idx, self.exact.getNumber(4, c_idx) + self.exact.getNumber(5, c_idx) + self.exact.getNumber(6, c_idx) + self.exact.getNumber(7, c_idx))
  64.                 self.round1000.setItem(9, c_idx, round(self.exact.getItem(9, c_idx) / 1000))
  65.             if self.exact.getItem(11, c_idx) is not None:
  66.                 self.exact.setItem(20, c_idx, self.exact.getNumber(11, c_idx) + self.exact.getNumber(15, c_idx) + self.exact.getNumber(16, c_idx) + self.exact.getNumber(18, c_idx))
  67.                 self.round1000.setItem(20, c_idx, round(self.exact.getNumber(20, c_idx) / 1000))
  68.  
  69.             sum29 = sum([self.exact.getNumber(r_idx, c_idx) for r_idx in range(22, 28+1)])
  70.             self.exact.setItem(29, c_idx, sum29)
  71.             self.round1000.setItem(29, c_idx, round(self.exact.getItem(29, c_idx) / 1000))
  72.             sum31 = sum([self.exact.getNumber(r_idx, c_idx) for r_idx in [9, 20, 29, 30]])
  73.             self.exact.setItem(31, c_idx, sum31)
  74.             self.round1000.setItem(31, c_idx, round(self.exact.getItem(31, c_idx) / 1000))
  75.         self.exact.setItem(31, 9, mapped_calculations.get_amort_expenses())
  76.         self.round1000.setItem(31, 9, round(self.exact.getItem(31, 9) / 1000))
  77.         self.exact.setItem(31, 15, mapped_calculations.get_long_assets())
  78.         self.round1000.setItem(31, 15, round(self.exact.getItem(31, 15) / 1000))
  79.  
  80.     def get_round1000(self):
  81.         return self.round1000
  82.  
  83.     def get_exact(self):
  84.         return self.exact
  85.  
  86.     def get_acc_rec_da(self):
  87.         return self.acc_rec_da
  88.  
  89.     def get_acc_rec_da_init_values(self):
  90.         return {
  91.             'prd': {'ns': 0, 'ns_amo': 0, 'assets': [], 'amort': [], 'assets_re': {'inc': 0.0, 'dec': 0.0, 'diff': 0},
  92.                     'amort_re': {'inc': 0.0, 'dec': 0.0, 'diff': 0}},
  93.             'pp': {'ns': 0, 'ns_amo': 0, 'assets': [], 'amort': [], 'assets_re': {'inc': 0.0, 'dec': 0.0, 'diff': 0},
  94.                    'amort_re': {'inc': 0.0, 'dec': 0.0, 'diff': 0}},
  95.             'tr': {'ns': 0, 'ns_amo': 0, 'assets': [], 'amort': [], 'assets_re': {'inc': 0.0, 'dec': 0.0, 'diff': 0},
  96.                    'amort_re': {'inc': 0.0, 'dec': 0.0, 'diff': 0}},
  97.             'rpna': {'ns': 0, 'ns_amo': 0, 'assets': [], 'amort': [], 'assets_re': {'inc': 0.0, 'dec': 0.0, 'diff': 0},
  98.                      'amort_re': {'inc': 0.0, 'dec': 0.0, 'diff': 0}},
  99.             'adv': {'ns': 0, 'ns_amo': 0, 'assets': [], 'amort': [], 'assets_re': {'inc': 0.0, 'dec': 0.0, 'diff': 0},
  100.                     'amort_re': {'inc': 0.0, 'dec': 0.0, 'diff': 0}},
  101.             # -------------------------------------------------------------------
  102.             'pdr': {'ns': 0, 'ns_amo': 0, 'assets': [], 'amort': [], 'assets_re': {'inc': 0.0, 'dec': 0.0, 'diff': 0},
  103.                     'amort_re': {'inc': 0.0, 'dec': 0.0, 'diff': 0}},
  104.             'z': {'ns': 0, 'ns_amo': 0, 'assets': [], 'amort': [], 'assets_re': {'inc': 0.0, 'dec': 0.0, 'diff': 0},
  105.                   'amort_re': {'inc': 0.0, 'dec': 0.0, 'diff': 0}},
  106.             'pz': {'ns': 0, 'ns_amo': 0, 'assets': [], 'amort': [], 'assets_re': {'inc': 0.0, 'dec': 0.0, 'diff': 0},
  107.                    'amort_re': {'inc': 0.0, 'dec': 0.0, 'diff': 0}},
  108.             's': {'ns': 0, 'ns_amo': 0, 'assets': [], 'amort': [], 'assets_re': {'inc': 0.0, 'dec': 0.0, 'diff': 0},
  109.                   'amort_re': {'inc': 0.0, 'dec': 0.0, 'diff': 0}},
  110.             'm': {'ns': 0, 'ns_amo': 0, 'assets': [], 'amort': [], 'assets_re': {'inc': 0.0, 'dec': 0.0, 'diff': 0},
  111.                   'amort_re': {'inc': 0.0, 'dec': 0.0, 'diff': 0}},
  112.             'sdr': {'ns': 0, 'ns_amo': 0, 'assets': [], 'amort': [], 'assets_re': {'inc': 0.0, 'dec': 0.0, 'diff': 0},
  113.                     'amort_re': {'inc': 0.0, 'dec': .00, 'diff': 0}},
  114.             'ts': {'ns': 0, 'ns_amo': 0, 'assets': [], 'amort': [], 'assets_re': {'inc': 0.0, 'dec': 0.0, 'diff': 0},
  115.                    'amort_re': {'inc': 0.0, 'dec': 0.0, 'diff': 0}},
  116.             'rpma': {'ns': 0, 'ns_amo': 0, 'assets': [], 'amort': [], 'assets_re': {'inc': 0.0, 'dec': 0.0, 'diff': 0},
  117.                      'amort_re': {'inc': 0.0, 'dec': 0.0, 'diff': 0}},
  118.             'advm': {'ns': 0, 'ns_amo': 0, 'assets': [], 'amort': [], 'assets_re': {'inc': 0.0, 'dec': 0.0, 'diff': 0},
  119.                      'amort_re': {'inc': 0.0, 'dec': 0.0, 'diff': 0}},
  120.             # -------------------------------------------------------------------
  121.             'adp': {'ns': 0, 'ns_amo': 0, 'assets': [], 'amort': [], 'assets_re': {'inc': 0.0, 'dec': 0.0, 'diff': 0},
  122.                     'amort_re': {'inc': 0, 'dec': 0, 'diff': 0}},
  123.             'pzp': {'ns': 0, 'ns_amo': 0, 'assets': [], 'amort': [], 'assets_re': {'inc': 0.0, 'dec': 0.0, 'diff': 0},
  124.                     'amort_re': {'inc': 0.0, 'dec': 0.0, 'diff': 0}},
  125.             'adas': {'ns': 0, 'ns_amo': 0, 'assets': [], 'amort': [], 'assets_re': {'inc': 0.0, 'dec': 0.0, 'diff': 0},
  126.                      'amort_re': {'inc': 0.0, 'dec': 0.0, 'diff': 0}},
  127.             'pzas': {'ns': 0, 'ns_amo': 0, 'assets': [], 'amort': [], 'assets_re': {'inc': 0.0, 'dec': 0.0, 'diff': 0},
  128.                      'amort_re': {'inc': 0.0, 'dec': 0.0, 'diff': 0}},
  129.             'di': {'ns': 0, 'ns_amo': 0, 'assets': [], 'amort': [], 'assets_re': {'inc': 0.0, 'dec': 0.0, 'diff': 0},
  130.                    'amort_re': {'inc': 0.0, 'dec': 0.0, 'diff': 0}},
  131.             'drz': {'ns': 0, 'ns_amo': 0, 'assets': [], 'amort': [], 'assets_re': {'inc': 0.0, 'dec': 0.0, 'diff': 0},
  132.                     'amort_re': {'inc': 0.0, 'dec': 0.0, 'diff': 0}},
  133.             'isa': {'ns': 0, 'ns_amo': 0, 'assets': [], 'amort': [], 'assets_re': {'inc': 0.0, 'dec': 0.0, 'diff': 0},
  134.                     'amort_re': {'inc': 0.0, 'dec': 0.0, 'diff': 0}},
  135.             # --------------------------
  136.             'ltax': {'ns': 0, 'ns_amo': 0, 'assets': [], 'amort': [], 'assets_re': {'inc': 0.0, 'dec': 0.0, 'diff': 0},
  137.                      'amort_re': {'inc': 0.0, 'dec': 0.0, 'diff': 0}}
  138.         }
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement