Advertisement
ALEXANDAR_GEORGIEV

mapped_acc_calculations

Dec 8th, 2022 (edited)
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 9.45 KB | Source Code | 0 0
  1. from account_tree import *
  2. from excel_acc_data import *
  3.  
  4.  
  5. class MappedCalculations:
  6.     def __init__(self):
  7.         # прочитаме маркировките на сметките
  8.         mapped_acc_data = MappedAccData()
  9.         mapped_acc_data.read_json()
  10.         self.mapped_accounts = mapped_acc_data.get_mapped_acc()
  11.         # print("TrialBalance: self.mapped_acc", self.mapped_accounts)
  12.         # прочитаме ескеслксите данни
  13.         self.excel_acc_data = ExcelAccData()
  14.         self.excel_acc_data.convert_json_data()
  15.         self.acc_data_bycode = self.excel_acc_data.get_acc_data_bycode()
  16.         self.min_top_group_digits = self.excel_acc_data.get_min_top_group_digits()
  17.         self.max_top_group_digits = self.excel_acc_data.get_max_top_group_digits()
  18.         self.max_groups = self.excel_acc_data.get_max_groups()
  19.         self.acc_tree = AccountTree()
  20.         for acc_code in self.acc_data_bycode:
  21.             self.acc_tree.add_code(acc_code)    # Захранваме наследственото дърво
  22.  
  23.     def are_all_acc_mapped(self):    # Проверка дали всички сметки са маркирани
  24.         unmapped_acc = self.acc_tree.get_unmapped_acc(self.mapped_accounts)
  25.         # print("unmapped_acc", unmapped_acc)
  26.         if len(unmapped_acc) == 0:
  27.             return True
  28.         return False
  29.  
  30.     # -------------- Калкулации по вид на сметката
  31.     def sum_by_type(self, type_acc):
  32.         # # TODO -> Да намерим всички сметки, които са от търсения вид
  33.         list_find_acc_bytype = []
  34.         all_mapped_accounts = []    # Кодовете на всички маркирани сметки
  35.         for mapped_acc in self.mapped_accounts:
  36.             if mapped_acc not in all_mapped_accounts:
  37.                 all_mapped_accounts.append(mapped_acc)
  38.         for account in all_mapped_accounts:
  39.             if type_acc in self.mapped_accounts[account] and len(self.mapped_accounts[account]) == 1:
  40.                 list_find_acc_bytype.append(account)    # Намерихме сметките, които са от търсения вид
  41.         # # TODO -> Търсим всички листа, които са търсения вид
  42.         list_leaves = self.acc_tree.get_leaves_bycode(list_find_acc_bytype)     # Намерихме листата на сметките
  43.         # print(f'list_leaves by {type_acc}: ', list_leaves)
  44.         # # # TODO -> Да вземем само тези, които имат дебитни начални салда
  45.         sum_open_c = sum_open_d = sum_turn_d = sum_turn_c = sum_close_d = sum_close_c = 0
  46.         for acc_code in list_leaves:
  47.             if acc_code in self.acc_data_bycode:
  48.                 sum_open_c += self.acc_data_bycode[acc_code]["open_c"]
  49.                 sum_open_d += self.acc_data_bycode[acc_code]["open_d"]
  50.                 sum_turn_d += self.acc_data_bycode[acc_code]["turn_d"]
  51.                 sum_turn_c += self.acc_data_bycode[acc_code]["turn_c"]
  52.                 sum_close_d += self.acc_data_bycode[acc_code]["close_d"]
  53.                 sum_close_c += self.acc_data_bycode[acc_code]["close_c"]
  54.         return {"od": sum_open_d, "oc": sum_open_c,
  55.                 "td": sum_turn_d, "tc": sum_turn_c,
  56.                 "cd": sum_close_d, "cc": sum_close_c}
  57.  
  58.     def get_equity(self):
  59.         sums = self.sum_by_type("СК")
  60.         equity = sums["cc"] - sums["cd"]
  61.         # print('diff: ', equity)
  62.         return equity
  63.  
  64. # -------------- Калкулации по колони
  65.     def sum_of_all_leaves(self):
  66.         sum_open_d = sum_open_c = sum_turn_d = sum_turn_c = sum_close_d = sum_close_c = 0
  67.         list_mapped_leaves = self.acc_tree.get_leaves()
  68.         for leaf in list_mapped_leaves:
  69.             if leaf in self.acc_data_bycode:
  70.                 sum_open_d += self.acc_data_bycode[leaf]["open_d"]
  71.                 sum_open_c += self.acc_data_bycode[leaf]["open_c"]
  72.                 sum_turn_d += self.acc_data_bycode[leaf]["turn_d"]
  73.                 sum_turn_c += self.acc_data_bycode[leaf]["turn_c"]
  74.                 sum_close_d += self.acc_data_bycode[leaf]["close_d"]
  75.                 sum_close_c += self.acc_data_bycode[leaf]["close_c"]
  76.         sums = {"od": sum_open_d, "oc": sum_open_c,
  77.                 "td": sum_turn_d, "tc": sum_turn_c,
  78.                 "cd": sum_close_d, "cc": sum_close_c}
  79.         return sums
  80.  
  81.     def get_balance_amount(self):
  82.         sums_bytype = self.sum_by_type("СК")
  83.         losses = sums_bytype["cd"]
  84.         sums_bytype = self.sum_by_type("ДА")
  85.         amortization = sums_bytype['cc']
  86.         # TODO -> Обща сума на всички сметки "cc": sum_close_c
  87.         sums_all_accounts = self.sum_of_all_leaves()
  88.         close_c = sums_all_accounts['cc']
  89.         liabilities = close_c - losses - amortization
  90.         # print('close_c: ', f'{close_c:.2f}')
  91.         # print('losses: ', f'{losses:.2f}')
  92.         # print('amortization: ', f'{amortization:.2f}')
  93.         # print('liabilities: ', f'{liabilities:.2f}')
  94.         # return liabilities
  95.  
  96.     def get_income_money_longassests(self):
  97.         tax_temporary_asset = 0
  98.         tax_temporary_passive = 0
  99.         sums_bytype = self.sum_by_type("Пх")
  100.         income = sums_bytype["tc"]
  101.         sums_bytype = self.sum_by_type("Пари")
  102.         money = sums_bytype['cd']
  103.         sums_bytype = self.sum_by_type("ДА")
  104.         assets = sums_bytype['cd']
  105.         amortization = sums_bytype['cc']
  106.         sums_bytype = self.sum_by_type("Дан А/П")
  107.         tax_assets = sums_bytype['cd']
  108.         tax_liabilities = sums_bytype['cc']
  109.         if tax_assets >= tax_liabilities:
  110.             tax_temporary_asset = tax_assets - tax_liabilities
  111.         else:
  112.             tax_temporary_passive = tax_liabilities - tax_assets
  113.         long_assets = assets - amortization + tax_temporary_asset
  114.         return income, money, long_assets
  115.  
  116.     def get_tax_assets(self):
  117.         '''Да се намерят листата на сметките, маркирани като "Дан А/П"
  118.         или бащата на сметките, маркирани като "Дан А/П" в който има само "Дан А/П"
  119.         и ако салдото е дебитно, да се добави към ДА,
  120.         ако салдото е кредитно, да се добави към Провизии'''
  121.         pass
  122.  
  123.     def det_long_assets(self):
  124.         '''Да се намерят сумите на сметките, маркирани като ДА + дебитно салдо на "Дан А/П"'''
  125.         pass
  126.  
  127.     def sum_by_accs(self, code_accs):   # code_accs is Tuple
  128.         # # TODO -> Да намерим всички сметки, които са от търсения вид
  129.         # list_find_acc_bytype = []
  130.         # all_mapped_accounts = []    # Кодовете на всички маркирани сметки
  131.  
  132.         # # # TODO ->
  133.         sum_open_c = sum_open_d = sum_turn_d = sum_turn_c = sum_close_d = sum_close_c = 0
  134.         for acc_code in code_accs:  # code_accs is Tuple
  135.  
  136.             if acc_code in self.acc_data_bycode:
  137.                 sum_open_c += self.acc_data_bycode[acc_code]["open_c"]
  138.                 sum_open_d += self.acc_data_bycode[acc_code]["open_d"]
  139.                 sum_turn_d += self.acc_data_bycode[acc_code]["turn_d"]
  140.                 sum_turn_c += self.acc_data_bycode[acc_code]["turn_c"]
  141.                 sum_close_d += self.acc_data_bycode[acc_code]["close_d"]
  142.                 sum_close_c += self.acc_data_bycode[acc_code]["close_c"]
  143.         return {"od": round(sum_open_d, 2), "oc": round(sum_open_c, 2),
  144.                 "td": round(sum_turn_d, 2), "tc": round(sum_turn_c, 2),
  145.                 "cd": round(sum_close_d, 2), "cc": round(sum_close_c, 2)}
  146.  
  147.     # TODO -> НОВ КЛАС ЗА ДОБАВЕНИТЕ СМЕТКИ И КАЛКУЛАЦИИ
  148.     def get_sum_list_accounts(self, dict_accs):
  149.         dict_sum_in_entry = {}
  150.         dict_sum_in_entry.clear()
  151.         dict_sum_all_entries = {'total': {'od': 0, 'oc': 0, 'td': 0, 'tc': 0, 'cd': 0, 'cc': 0}}
  152.         # Трябва да отделя сметките от речника в лист
  153.         # {'e_prd': ('207', '203'), 'e_pp': (), 'e_tr': ('208',), 'e_rpna': (), 'e_adv': ()}
  154.         for entry_name in dict_accs:
  155.             tuple_entry = dict_accs[entry_name]
  156.             sums_by_columns = self.sum_by_accs(tuple_entry)
  157.             dict_sum_in_entry[entry_name] = sums_by_columns
  158.             dict_sum_all_entries['total']['od'] += dict_sum_in_entry[entry_name]['od']
  159.             dict_sum_all_entries['total']['oc'] += dict_sum_in_entry[entry_name]['oc']
  160.             dict_sum_all_entries['total']['td'] += dict_sum_in_entry[entry_name]['td']
  161.             dict_sum_all_entries['total']['tc'] += dict_sum_in_entry[entry_name]['tc']
  162.             dict_sum_all_entries['total']['cd'] += dict_sum_in_entry[entry_name]['cd']
  163.             dict_sum_all_entries['total']['cc'] += dict_sum_in_entry[entry_name]['cc']
  164.         # : 96619.01, 'oc': 0.0, 'td': 45001.97, 'tc': 0.0, 'cd': 141620.98, 'cc': 0.0}
  165.         return dict_sum_in_entry, dict_sum_all_entries
  166.  
  167.  
  168.  
  169.  
  170. if __name__ == '__main__':
  171.     test = MappedCalculations()
  172.     # test.sum_by_type('СК')
  173.     # test.get_equity()
  174.     # test.get_balance_amount()
  175.     dict_test ={'e_prd': ('207', '203'), 'e_pp': (), 'e_tr': ('208',), 'e_rpna': (), 'e_adv': ()}
  176.     new_dict = test.get_sum_list_accounts(dict_test)
  177.     print('new_dict: ', new_dict)
  178.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement