Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from account_tree import *
- from excel_acc_data import *
- class MappedCalculations:
- def __init__(self):
- # прочитаме маркировките на сметките
- mapped_acc_data = MappedAccData()
- mapped_acc_data.read_json()
- self.mapped_accounts = mapped_acc_data.get_mapped_acc()
- # print("TrialBalance: self.mapped_acc", self.mapped_accounts)
- # прочитаме ескеслксите данни
- self.excel_acc_data = ExcelAccData()
- self.excel_acc_data.convert_json_data()
- self.acc_data_bycode = self.excel_acc_data.get_acc_data_bycode()
- self.min_top_group_digits = self.excel_acc_data.get_min_top_group_digits()
- self.max_top_group_digits = self.excel_acc_data.get_max_top_group_digits()
- self.max_groups = self.excel_acc_data.get_max_groups()
- self.acc_tree = AccountTree()
- for acc_code in self.acc_data_bycode:
- self.acc_tree.add_code(acc_code) # Захранваме наследственото дърво
- def are_all_acc_mapped(self): # Проверка дали всички сметки са маркирани
- unmapped_acc = self.acc_tree.get_unmapped_acc(self.mapped_accounts)
- # print("unmapped_acc", unmapped_acc)
- if len(unmapped_acc) == 0:
- return True
- return False
- # -------------- Калкулации по вид на сметката
- def sum_by_type(self, type_acc):
- # # TODO -> Да намерим всички сметки, които са от търсения вид
- list_find_acc_bytype = []
- all_mapped_accounts = [] # Кодовете на всички маркирани сметки
- for mapped_acc in self.mapped_accounts:
- if mapped_acc not in all_mapped_accounts:
- all_mapped_accounts.append(mapped_acc)
- for account in all_mapped_accounts:
- if type_acc in self.mapped_accounts[account] and len(self.mapped_accounts[account]) == 1:
- list_find_acc_bytype.append(account) # Намерихме сметките, които са от търсения вид
- # # TODO -> Търсим всички листа, които са търсения вид
- list_leaves = self.acc_tree.get_leaves_bycode(list_find_acc_bytype) # Намерихме листата на сметките
- # print(f'list_leaves by {type_acc}: ', list_leaves)
- # # # TODO -> Да вземем само тези, които имат дебитни начални салда
- sum_open_c = sum_open_d = sum_turn_d = sum_turn_c = sum_close_d = sum_close_c = 0
- for acc_code in list_leaves:
- if acc_code in self.acc_data_bycode:
- sum_open_c += self.acc_data_bycode[acc_code]["open_c"]
- sum_open_d += self.acc_data_bycode[acc_code]["open_d"]
- sum_turn_d += self.acc_data_bycode[acc_code]["turn_d"]
- sum_turn_c += self.acc_data_bycode[acc_code]["turn_c"]
- sum_close_d += self.acc_data_bycode[acc_code]["close_d"]
- sum_close_c += self.acc_data_bycode[acc_code]["close_c"]
- return {"od": sum_open_d, "oc": sum_open_c,
- "td": sum_turn_d, "tc": sum_turn_c,
- "cd": sum_close_d, "cc": sum_close_c}
- def get_equity(self):
- sums = self.sum_by_type("СК")
- equity = sums["cc"] - sums["cd"]
- # print('diff: ', equity)
- return equity
- # -------------- Калкулации по колони
- def sum_of_all_leaves(self):
- sum_open_d = sum_open_c = sum_turn_d = sum_turn_c = sum_close_d = sum_close_c = 0
- list_mapped_leaves = self.acc_tree.get_leaves()
- for leaf in list_mapped_leaves:
- if leaf in self.acc_data_bycode:
- sum_open_d += self.acc_data_bycode[leaf]["open_d"]
- sum_open_c += self.acc_data_bycode[leaf]["open_c"]
- sum_turn_d += self.acc_data_bycode[leaf]["turn_d"]
- sum_turn_c += self.acc_data_bycode[leaf]["turn_c"]
- sum_close_d += self.acc_data_bycode[leaf]["close_d"]
- sum_close_c += self.acc_data_bycode[leaf]["close_c"]
- sums = {"od": sum_open_d, "oc": sum_open_c,
- "td": sum_turn_d, "tc": sum_turn_c,
- "cd": sum_close_d, "cc": sum_close_c}
- return sums
- def get_balance_amount(self):
- sums_bytype = self.sum_by_type("СК")
- losses = sums_bytype["cd"]
- sums_bytype = self.sum_by_type("ДА")
- amortization = sums_bytype['cc']
- # TODO -> Обща сума на всички сметки "cc": sum_close_c
- sums_all_accounts = self.sum_of_all_leaves()
- close_c = sums_all_accounts['cc']
- liabilities = close_c - losses - amortization
- # print('close_c: ', f'{close_c:.2f}')
- # print('losses: ', f'{losses:.2f}')
- # print('amortization: ', f'{amortization:.2f}')
- # print('liabilities: ', f'{liabilities:.2f}')
- # return liabilities
- def get_income_money_longassests(self):
- tax_temporary_asset = 0
- tax_temporary_passive = 0
- sums_bytype = self.sum_by_type("Пх")
- income = sums_bytype["tc"]
- sums_bytype = self.sum_by_type("Пари")
- money = sums_bytype['cd']
- sums_bytype = self.sum_by_type("ДА")
- assets = sums_bytype['cd']
- amortization = sums_bytype['cc']
- sums_bytype = self.sum_by_type("Дан А/П")
- tax_assets = sums_bytype['cd']
- tax_liabilities = sums_bytype['cc']
- if tax_assets >= tax_liabilities:
- tax_temporary_asset = tax_assets - tax_liabilities
- else:
- tax_temporary_passive = tax_liabilities - tax_assets
- long_assets = assets - amortization + tax_temporary_asset
- return income, money, long_assets
- def get_tax_assets(self):
- '''Да се намерят листата на сметките, маркирани като "Дан А/П"
- или бащата на сметките, маркирани като "Дан А/П" в който има само "Дан А/П"
- и ако салдото е дебитно, да се добави към ДА,
- ако салдото е кредитно, да се добави към Провизии'''
- pass
- def det_long_assets(self):
- '''Да се намерят сумите на сметките, маркирани като ДА + дебитно салдо на "Дан А/П"'''
- pass
- def sum_by_accs(self, code_accs): # code_accs is Tuple
- # # TODO -> Да намерим всички сметки, които са от търсения вид
- # list_find_acc_bytype = []
- # all_mapped_accounts = [] # Кодовете на всички маркирани сметки
- # # # TODO ->
- sum_open_c = sum_open_d = sum_turn_d = sum_turn_c = sum_close_d = sum_close_c = 0
- for acc_code in code_accs: # code_accs is Tuple
- if acc_code in self.acc_data_bycode:
- sum_open_c += self.acc_data_bycode[acc_code]["open_c"]
- sum_open_d += self.acc_data_bycode[acc_code]["open_d"]
- sum_turn_d += self.acc_data_bycode[acc_code]["turn_d"]
- sum_turn_c += self.acc_data_bycode[acc_code]["turn_c"]
- sum_close_d += self.acc_data_bycode[acc_code]["close_d"]
- sum_close_c += self.acc_data_bycode[acc_code]["close_c"]
- return {"od": round(sum_open_d, 2), "oc": round(sum_open_c, 2),
- "td": round(sum_turn_d, 2), "tc": round(sum_turn_c, 2),
- "cd": round(sum_close_d, 2), "cc": round(sum_close_c, 2)}
- # TODO -> НОВ КЛАС ЗА ДОБАВЕНИТЕ СМЕТКИ И КАЛКУЛАЦИИ
- def get_sum_list_accounts(self, dict_accs):
- dict_sum_in_entry = {}
- dict_sum_in_entry.clear()
- dict_sum_all_entries = {'total': {'od': 0, 'oc': 0, 'td': 0, 'tc': 0, 'cd': 0, 'cc': 0}}
- # Трябва да отделя сметките от речника в лист
- # {'e_prd': ('207', '203'), 'e_pp': (), 'e_tr': ('208',), 'e_rpna': (), 'e_adv': ()}
- for entry_name in dict_accs:
- tuple_entry = dict_accs[entry_name]
- sums_by_columns = self.sum_by_accs(tuple_entry)
- dict_sum_in_entry[entry_name] = sums_by_columns
- dict_sum_all_entries['total']['od'] += dict_sum_in_entry[entry_name]['od']
- dict_sum_all_entries['total']['oc'] += dict_sum_in_entry[entry_name]['oc']
- dict_sum_all_entries['total']['td'] += dict_sum_in_entry[entry_name]['td']
- dict_sum_all_entries['total']['tc'] += dict_sum_in_entry[entry_name]['tc']
- dict_sum_all_entries['total']['cd'] += dict_sum_in_entry[entry_name]['cd']
- dict_sum_all_entries['total']['cc'] += dict_sum_in_entry[entry_name]['cc']
- # : 96619.01, 'oc': 0.0, 'td': 45001.97, 'tc': 0.0, 'cd': 141620.98, 'cc': 0.0}
- return dict_sum_in_entry, dict_sum_all_entries
- if __name__ == '__main__':
- test = MappedCalculations()
- # test.sum_by_type('СК')
- # test.get_equity()
- # test.get_balance_amount()
- dict_test ={'e_prd': ('207', '203'), 'e_pp': (), 'e_tr': ('208',), 'e_rpna': (), 'e_adv': ()}
- new_dict = test.get_sum_list_accounts(dict_test)
- print('new_dict: ', new_dict)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement