Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- from widget_factory import *
- from mapped_acc_calculations import *
- from json_file_io import JsonFileIo
- from Opiti.from_excel.classes.global_inc import registry
- class Expenses(Tk):
- def __init__(self):
- Tk.__init__(self)
- self.account_tree = AccountTree()
- self.widget_factory = WidgetsFactory()
- self.excel_acc_data = ExcelAccData()
- self.mapped_calculations = MappedCalculations()
- 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()
- json_file_io = JsonFileIo(file_name=registry["mapped_account_file_name"])
- acc_data_mapped = json_file_io.read_content() # {"121": ["СК"], "121-13": ["СК"], "121-14": ["СК"],
- if acc_data_mapped is None:
- print("?? acc_data_mapped is NONE!!!")
- self.acc_data_mapped_da = {} # Речник с маркираните сметки с вид 'ДА'
- for acc_code in self.acc_data_bycode:
- self.account_tree.add_code(acc_code) # Захранваме наследственото дърво
- self.acc_data = []
- self.max_depth_rx = 0
- for acc_code in acc_data_mapped:
- acc_types = acc_data_mapped[acc_code]
- if 'Рх' in acc_types and len(acc_types) == 1:
- self.acc_data_mapped_da[acc_code] = acc_data_mapped[acc_code]
- depth = self.account_tree.get_depth(acc_code)
- if depth > self.max_depth_rx:
- self.max_depth_rx = depth
- for acc_code in self.acc_data_bycode:
- if acc_code in self.acc_data_mapped_da:
- acc_row = self.acc_data_bycode[acc_code]
- self.acc_data.append(acc_row)
- # -----------------------
- self.acc_rec_rx = {
- 'sm': {'ns': 0, 'ns_amo': 0, 'assets': [], 'amort': [], 'assets_re': {'inc': 0, 'dec': 0, 'diff': 0},
- 'amort_re': {'inc': 0, 'dec': 0, 'diff': 0}},
- 'vu': {'ns': 0, 'ns_amo': 0, 'assets': [], 'amort': [], 'assets_re': {'inc': 0, 'dec': 0, 'diff': 0},
- 'amort_re': {'inc': 0, 'dec': 0, 'diff': 0}},
- 'a': {'ns': 0, 'ns_amo': 0, 'assets': [], 'amort': [], 'assets_re': {'inc': 0, 'dec': 0, 'diff': 0},
- 'amort_re': {'inc': 0, 'dec': 0, 'diff': 0}},
- 'po': {'ns': 0, 'ns_amo': 0, 'assets': [], 'amort': [], 'assets_re': {'inc': 0, 'dec': 0, 'diff': 0},
- 'amort_re': {'inc': 0, 'dec': 0, 'diff': 0}},
- 'dro': {'ns': 0, 'ns_amo': 0, 'assets': [], 'amort': [], 'assets_re': {'inc': 0, 'dec': 0, 'diff': 0},
- 'amort_re': {'inc': 0, 'dec': 0, 'diff': 0}},
- 'rd': {'ns': 0, 'ns_amo': 0, 'assets': [], 'amort': [], 'assets_re': {'inc': 0, 'dec': 0, 'diff': 0},
- 'amort_re': {'inc': 0, 'dec': 0, 'diff': 0}},
- 'ona': {'ns': 0, 'ns_amo': 0, 'assets': [], 'amort': [], 'assets_re': {'inc': 0, 'dec': 0, 'diff': 0},
- 'amort_re': {'inc': 0, 'dec': 0, 'diff': 0}},
- 'ota': {'ns': 0, 'ns_amo': 0, 'assets': [], 'amort': [], 'assets_re': {'inc': 0, 'dec': 0, 'diff': 0},
- 'amort_re': {'inc': 0, 'dec': 0, 'diff': 0}},
- 'pr': {'ns': 0, 'ns_amo': 0, 'assets': [], 'amort': [], 'assets_re': {'inc': 0, 'dec': 0, 'diff': 0},
- 'amort_re': {'inc': 0, 'dec': 0, 'diff': 0}},
- 'drr': {'ns': 0, 'ns_amo': 0, 'assets': [], 'amort': [], 'assets_re': {'inc': 0, 'dec': 0, 'diff': 0},
- 'amort_re': {'inc': 0, 'dec': 0, 'diff': 0}},
- 'rod': {'ns': 0, 'ns_amo': 0, 'assets': [], 'amort': [], 'assets_re': {'inc': 0, 'dec': 0, 'diff': 0},
- 'amort_re': {'inc': 0, 'dec': 0, 'diff': 0}},
- 'rsd': {'ns': 0, 'ns_amo': 0, 'assets': [], 'amort': [], 'assets_re': {'inc': 0, 'dec': 0, 'diff': 0},
- 'amort_re': {'inc': 0, 'dec': 0, 'diff': 0}},
- 'rtd': {'ns': 0, 'ns_amo': 0, 'assets': [], 'amort': [], 'assets_re': {'inc': 0, 'dec': 0, 'diff': 0},
- 'amort_re': {'inc': 0, 'dec': 0, 'diff': 0}},
- 'rad': {'ns': 0, 'ns_amo': 0, 'assets': [], 'amort': [], 'assets_re': {'inc': 0, 'dec': 0, 'diff': 0},
- 'amort_re': {'inc': 0, 'dec': 0, 'diff': 0}},
- 'rud': {'ns': 0, 'ns_amo': 0, 'assets': [], 'amort': [], 'assets_re': {'inc': 0, 'dec': 0, 'diff': 0},
- 'amort_re': {'inc': 0, 'dec': 0, 'diff': 0}},
- 'rlk': {'ns': 0, 'ns_amo': 0, 'assets': [], 'amort': [], 'assets_re': {'inc': 0, 'dec': 0, 'diff': 0},
- 'amort_re': {'inc': 0, 'dec': 0, 'diff': 0}},
- 'rldopk': {'ns': 0, 'ns_amo': 0, 'assets': [], 'amort': [], 'assets_re': {'inc': 0, 'dec': 0, 'diff': 0},
- 'amort_re': {'inc': 0, 'dec': 0, 'diff': 0}},
- 'rdrl': {'ns': 0, 'ns_amo': 0, 'assets': [], 'amort': [], 'assets_re': {'inc': 0, 'dec': 0, 'diff': 0},
- 'amort_re': {'inc': 0, 'dec': 0, 'diff': 0}},
- 'rov': {'ns': 0, 'ns_amo': 0, 'assets': [], 'amort': [], 'assets_re': {'inc': 0, 'dec': 0, 'diff': 0},
- 'amort_re': {'inc': 0, 'dec': 0, 'diff': 0}},
- 'rofa': {'ns': 0, 'ns_amo': 0, 'assets': [], 'amort': [], 'assets_re': {'inc': 0, 'dec': 0, 'diff': 0},
- 'amort_re': {'inc': 0, 'dec': 0, 'diff': 0}},
- 'rora': {'ns': 0, 'ns_amo': 0, 'assets': [], 'amort': [], 'assets_re': {'inc': 0, 'dec': 0, 'diff': 0},
- 'amort_re': {'inc': 0, 'dec': 0, 'diff': 0}},
- 'ropfa': {'ns': 0, 'ns_amo': 0, 'assets': [], 'amort': [], 'assets_re': {'inc': 0, 'dec': 0, 'diff': 0},
- 'amort_re': {'inc': 0, 'dec': 0, 'diff': 0}},
- 'drfr': {'ns': 0, 'ns_amo': 0, 'assets': [], 'amort': [], 'assets_re': {'inc': 0, 'dec': 0, 'diff': 0},
- 'amort_re': {'inc': 0, 'dec': 0, 'diff': 0}},
- 'nzpr': {'ns': 0, 'ns_amo': 0, 'assets': [], 'amort': [], 'assets_re': {'inc': 0, 'dec': 0, 'diff': 0},
- 'amort_re': {'inc': 0, 'dec': 0, 'diff': 0}},
- 'nnpr': {'ns': 0, 'ns_amo': 0, 'assets': [], 'amort': [], 'assets_re': {'inc': 0, 'dec': 0, 'diff': 0},
- 'amort_re': {'inc': 0, 'dec': 0, 'diff': 0}},
- 'bsna': {'ns': 0, 'ns_amo': 0, 'assets': [], 'amort': [], 'assets_re': {'inc': 0, 'dec': 0, 'diff': 0},
- 'amort_re': {'inc': 0, 'dec': 0, 'diff': 0}},
- 'bsta': {'ns': 0, 'ns_amo': 0, 'assets': [], 'amort': [], 'assets_re': {'inc': 0, 'dec': 0, 'diff': 0},
- 'amort_re': {'inc': 0, 'dec': 0, 'diff': 0}},
- 'rtax': {'ns': 0, 'ns_amo': 0, 'assets': [], 'amort': [], 'assets_re': {'inc': 0, 'dec': 0, 'diff': 0},
- 'amort_re': {'inc': 0, 'dec': 0, 'diff': 0}},
- 'alttax': {'ns': 0, 'ns_amo': 0, 'assets': [], 'amort': [], 'assets_re': {'inc': 0, 'dec': 0, 'diff': 0},
- 'amort_re': {'inc': 0, 'dec': 0, 'diff': 0}},
- }
- # -------------------------
- self.check_assets = IntVar() # Radiobutton tab - преоценка активи
- self.check_amort = IntVar() # Radiobutton tab - преоценка амортизации
- self.last_entry = Entry() # Четене на Entry code
- self.acc_data = []
- self.scr_bar = None
- self.tab_names = {
- "act": "Ръчно попълване",
- "amort": "Автоматично попълване",
- # "act_p": "Финансови разходи",
- # "amort_p": "Коригиращи суми",
- }
- self.current_tab = ''
- self.open = 'str_open_d'
- self.close = 'str_close_d'
- self.term_dc = 'debit'
- self.term = None
- self.all_accounts = []
- self.list_unadded_accs = []
- self.unadded_spin = ''
- self.selected_accs = [] # Данните, които трябва да се запишат във файл за да се маркират сметките в Treeview
- self.selected_accs_amo = [] # Маркирани сметки в Treeview АМортизации
- self.dict_entries = {} # Списък с Ентритата на Активите
- self.dict_entries_amo = {} # Списък с Ентрита на Амортизации
- self.get_sums = {}
- self.get_sums_amo = {}
- self.get_total = {'total': {'od': 0.0, 'oc': 0.0, 'td': 0.0, 'tc': 0.0, 'cd': 0.0, 'cc': 0.0}}
- self.get_total_amo = {'total': {'od': 0.0, 'oc': 0.0, 'td': 0.0, 'tc': 0.0, 'cd': 0.0, 'cc': 0.0}}
- self.user_ns = {'sm': 0, 'vu': 0, 'a': 0, 'po': 0, 'dro': 0, 'rd': 0, 'ona': 0, 'ota': 0, 'pr': 0, 'drr': 0,}
- self.user_ns_amo = {'di': 0}
- self.assets_re = {'adp': {'inc': 0, 'dec': 0}, 'pzp': {'inc': 0, 'dec': 0}, 'adas': {'inc': 0, 'dec': 0}, 'pzas': {'inc': 0, 'dec': 0}, 'di': {'inc': 0, 'dec': 0}, 'drz': {'inc': 0, 'dec': 0}, 'isa': {'inc': 0, 'dec': 0}}
- self.amort_re = {'di': {'inc': 0, 'dec': 0}}
- self.pop_message_answer = ''
- # TODO -> Главен прозорец
- self.title('Продадени активи') # TODO -> Главен прозорец
- self.geometry('700x410+200+150') # 480
- self.resizable(True, False)
- self.attributes('-topmost', 'true')
- # TODO -> Notebook
- self.tabs = ttk.Notebook(self) # TODO -> Табове
- self.tabs.pack(pady=(1, 56), anchor='w') # class_, cursor, padding, relief, style, takefocus
- self.tab1 = Frame(self.tabs, width=650, height=300, relief=GROOVE, borderwidth=5)
- self.tab1.pack() # fill=”X” specifies, fill=”Y”
- self.tabs.add(self.tab1, text=self.tab_names['act'], padding=(8, 10)) #
- self.tab2 = Frame(self.tabs, width=550, height=300, relief=GROOVE, borderwidth=5, bg='white')
- self.tab2.pack(fill='both', expand=1)
- self.tabs.add(self.tab2, text=self.tab_names['amort'], padding=(8, 10))
- # self.tab3 = Frame(self.tabs, width=550, height=300, relief=GROOVE, borderwidth=5, bg='mint cream')
- # self.tab3.pack(fill='both', expand=1)
- # self.tabs.add(self.tab3, text=self.tab_names['act_p'], padding=(2, 10))
- # self.tab4 = Frame(self.tabs, width=550, height=300, relief=GROOVE, borderwidth=5, bg='lemon chiffon')
- # self.tab4.pack(fill='both', expand=1)
- # self.tabs.add(self.tab4, text=self.tab_names['amort_p'], padding=(2, 10)) #
- # self.tabs.bind('<<NotebookTabChanged>>', self.get_tab)
- # TODO -> LABELS
- self.widget_factory.get_label_un(self.tab1, 'Отписани нетекущи активи', 20, 20, 'w', 24, 'blue', bg_border='red')
- self.widget_factory.get_label_un(self.tab1, 'Отписани активи', 20, 50, 'w', 14, bg_border='green')
- self.l_open_adp = self.widget_factory.get_label_un(self.tab1, '0', 40, 80, 'e', 11, 'black', bg_border='green', j='left', name='adp')
- self.widget_factory.get_label_un(self.tab1, 'Отписана амортизация', 180, 50, 'w', 19, bg_border='green', j='left')
- self.l_open_adp = self.widget_factory.get_label_un(self.tab1, '0', 234, 80, 'e', 11, 'black', bg_border='green', j='left', name='adp')
- self.widget_factory.get_label_un(self.tab1, 'Балансова стойност', 380, 50, 'w', 19, bg_border='green')
- self.l_open_adp = self.widget_factory.get_label_un(self.tab1, '0', 380, 80, 'e', 4, 'black', bg_border='green', j='left', name='adp')
- self.l_open_adp = self.widget_factory.get_label_un(self.tab1, '0', 432, 80, 'e', 11, 'black', bg_border='green', j='left', name='adp')
- # # TODO -> CHECKBUTTON
- # self.check_1 = Checkbutton(self.tab1, variable=self.check_assets, command=lambda: self.act_c1(), text='Прехвърляне')
- # self.check_1.place(x=520, y=130)
- self.widget_factory.get_label_un(self.tab1, 'Продадени нетекущи активи', 20, 130, 'w', 24, 'blue', bg_border='red')
- self.widget_factory.get_label_un(self.tab1, 'Продадени активи', 20, 160, 'w', 15, bg_border='green', j='left')
- self.user_adp = self.widget_factory.get_entry(self.tab1, 46, 200, 14, 'right', name='user_adp')
- self.widget_factory.get_label_un(self.tab1, 'Отписана амортизация', 180, 160, 'w', 19, bg_border='green', j='left')
- self.user_am = self.widget_factory.get_entry(self.tab1, 232, 200, 14, 'right', name='user_am')
- self.widget_factory.get_label_un(self.tab1, 'Балансова стойност', 380, 160, 'w', 19, bg_border='green')
- self.user_bs = self.widget_factory.get_entry(self.tab1, 380, 200, 4, 'right', name='user_bs')
- self.user_bals = self.widget_factory.get_entry(self.tab1, 434, 200, 14, 'right', name='user_bals')
- # TODO Разходи по дейност
- self.widget_factory.get_label_un(self.tab2, 'Движение на нетекущи активи', 20, 20, 'w', 22, 'blue', bg_color='white', bg_border='red')
- self.widget_factory.get_label_un(self.tab2, 'Разходи по дейности', 20, 50, 'w', 22, bg_color='white', bg_border='red')
- self.widget_factory.get_label_un(self.tab2, 'НС\n(хил.лв)', 275, 40, 'w', 6, 'black', bg_color='white', bg_border='red', j='center')
- self.widget_factory.get_label_un(self.tab2, 'НС\n(лева)', 340, 40, 'center', 11, 'black', bg_color='white', bg_border='red', j='center')
- self.widget_factory.get_label_un(self.tab2, 'с/ка:\n(код)', 460, 40, 'center', 4, 'black', bg_color='white', bg_border='green')
- self.widget_factory.get_label_un(self.tab2, '1. Отписани нетекущи активи', 20, 100, 'w', 28, bg_color='white', bg_border='green', j='left')
- self.widget_factory.get_label_un(self.tab2, '2. Отписана амортизация', 20, 150, 'w', 26, bg_color='white', bg_border='green', j='left')
- self.widget_factory.get_label_un(self.tab2, '3. Отписана балансова стойност', 20, 180, 'w', 26, bg_color='white', bg_border='green', j='left')
- self.widget_factory.get_label_un(self.tab2, '1.1 Продадени нетекущи активи', 20, 210, 'w', 26, bg_color='white', bg_border='green', j='left')
- self.widget_factory.get_label_un(self.tab2, '2.1 Отписана амортизация', 20, 240, 'w', 26, bg_color='white', bg_border='green')
- self.widget_factory.get_label_un(self.tab2, '3.1 Отписана балансова стойност', 20, 180, 'w', 26, bg_color='white', bg_border='green', j='left')
- # TODO -> Entries
- self.user_rod = self.widget_factory.get_entry(self.tab2, 280, 110, 5, 'right', name='user_rod')
- self.user_rod.bind("<KeyRelease>", lambda e: self.update_state_open_bal(self.user_rod, "rod", "td"))
- self.l_open_rod = self.widget_factory.get_label_un(self.tab2, '0', 340, 110, 'e', 11, 'black', bg_color='white',
- bg_border='green', j='left')
- self.e_rod = self.widget_factory.get_entry(self.tab2, 450, 110, 9, name='rod')
- self.e_rod.bind("<KeyRelease>", lambda e: self.on_entry_key_release(self.e_rod))
- self.e_rod.bind("<FocusIn>", lambda e: self.entry_on_focus(self.e_rod))
- self.user_rsd = self.widget_factory.get_entry(self.tab2, 280, 150, 5, 'right', name='user_rsd')
- self.user_rsd.bind("<KeyRelease>", lambda e: self.update_state_open_bal(self.user_rsd, "rsd", "td"))
- self.l_open_rsd = self.widget_factory.get_label_un(self.tab2, '0', 340, 150, 'e', 11, 'black', bg_color='white',
- bg_border='green', j='left')
- self.e_rsd = self.widget_factory.get_entry(self.tab2, 450, 150, 9, name='rsd')
- self.e_rsd.bind("<KeyRelease>", lambda e: self.on_entry_key_release(self.e_rsd))
- self.e_rsd.bind("<FocusIn>", lambda e: self.entry_on_focus(self.e_rsd))
- self.user_rtd = self.widget_factory.get_entry(self.tab2, 280, 180, 5, 'right', name='user_rtd')
- self.user_rtd.bind("<KeyRelease>", lambda e: self.update_state_open_bal(self.user_rtd, "rtd", "td"))
- self.l_open_rtd = self.widget_factory.get_label_un(self.tab2, '0', 340, 180, 'e', 11, 'black', bg_color='white',
- bg_border='green', j='left')
- self.e_rtd = self.widget_factory.get_entry(self.tab2, 450, 180, 9, name='rtd')
- self.e_rtd.bind("<KeyRelease>", lambda e: self.on_entry_key_release(self.e_rtd))
- self.e_rtd.bind("<FocusIn>", lambda e: self.entry_on_focus(self.e_rtd))
- self.user_rad = self.widget_factory.get_entry(self.tab2, 280, 210, 5, 'right', name='user_rad')
- self.user_rad.bind("<KeyRelease>", lambda e: self.update_state_open_bal(self.user_rad, "rad", "td"))
- self.l_open_rad = self.widget_factory.get_label_un(self.tab2, '0', 340, 210, 'e', 11, 'black', bg_color='white',
- bg_border='green', j='left')
- self.e_rad = self.widget_factory.get_entry(self.tab2, 450, 210, 9, name='rad')
- self.e_rad.bind("<KeyRelease>", lambda e: self.on_entry_key_release(self.e_rad))
- self.e_rad.bind("<FocusIn>", lambda e: self.entry_on_focus(self.e_rad))
- self.user_rud = self.widget_factory.get_entry(self.tab2, 280, 240, 5, 'right', name='user_rud')
- self.user_rud.bind("<KeyRelease>", lambda e: self.update_state_open_bal(self.user_rud, "rud", "td"))
- self.l_open_rud = self.widget_factory.get_label_un(self.tab2, '0', 340, 240, 'e', 11, 'black', bg_color='white',
- bg_border='green', j='left')
- self.e_rud = self.widget_factory.get_entry(self.tab2, 450, 240, 9, name='rud')
- self.e_rud.bind("<KeyRelease>", lambda e: self.on_entry_key_release(self.e_rud))
- self.e_rud.bind("<FocusIn>", lambda e: self.entry_on_focus(self.e_rud))
- # TODO -> DOWN LABELS
- self.widget_factory.get_label(self.tab2, 90, 430, 'В началното', 12, 'e', font=10, bg_color='white')
- self.widget_factory.get_label(self.tab2, 195, 430, 'Увеличение', 12, 'e', font=10, bg_color='white')
- self.widget_factory.get_label(self.tab2, 300, 430, 'Намаление', 12, 'e', font=10, bg_color='white')
- self.widget_factory.get_label(self.tab2, 410, 430, 'В края', 12, 'e', font=10, bg_color='white')
- self.widget_factory.get_label(self.tab2, 20, 450, 'Група III.:', 10, 'w', font=10, bg_color='white')
- self.l_amo_open_total = self.widget_factory.get_label(self.tab2, 90, 450, 0.0, 12, 'e', color='black',
- font=10, bg_color='white')
- self.l_amo_turn_d_total = self.widget_factory.get_label(self.tab2, 195, 450, 0.0, 12, 'e', color='black',
- font=10, bg_color='white')
- self.l_amo_turn_c_total = self.widget_factory.get_label(self.tab2, 300, 450, 0.0, 12, 'e', color='black',
- font=10, bg_color='white')
- self.l_amo_close_total = self.widget_factory.get_label(self.tab2, 410, 450, 0.0, 12, 'e', color='black',
- font=10, bg_color='white')
- # TODO Buttons
- # Button Помощ
- self.b_help = self.widget_factory.get_help_button(self, 20, 360)
- self.b_help.bind('<ButtonRelease-1>')
- # Button Корекции
- self.b_note = self.widget_factory.get_correction_button(self, 180, 360)
- self.b_note.bind('<ButtonRelease-1>', lambda e: self.on_correction())
- # Button Прехвърли
- self.b_add = self.widget_factory.get_save_button(self, 360, 360, text='ПРЕХВЪРЛИ') # 460, 435
- self.b_add.bind('<ButtonRelease-1>', lambda e: self.on_add())
- # Button Save
- self.b_save = self.widget_factory.get_ok_button(self, 465, 360)
- self.b_save.bind('<ButtonRelease-1>', lambda e: self.on_save())
- # Button Отказ
- self.b_exit = self.widget_factory.get_correction_esc(self, 565, 360)
- self.b_exit.config(command=self.destroy)
- # def get_tab(self, *args):
- # self.current_tab = self.tabs.tab(self.tabs.select(), "text")
- # # if self.current_tab == 'Активи' or self.current_tab == 'Преоценка активи':
- # self.open, self.close = 'str_open_d', 'str_close_d'
- # self.treeview_acc.heading('#3', text='НС Дебит ')
- # self.treeview_acc.heading('#6', text='КС Дебит ')
- # self.term_dc = 'debit'
- # # if self.current_tab == 'Активи':
- # self.treeview_acc.configure(selectmode='browse')
- # self.e_adp.focus_set()
- # self.b_add['state'] = 'normal'
- # self.b_note['state'] = 'normal'
- # # else:
- # # self.treeview_acc.configure(selectmode='none')
- # # self.b_note['state'] = 'disabled'
- #
- # self.fill_treeview(term_dc=self.term_dc)
- # self.fill_labels()
- def set_pop_message_answer(self, answer):
- self.pop_message_answer = answer
- def on_save(self):
- # TODO -> Попълваме Началното салдо, въведено от потребителя:
- # for entry in self.user_ns:
- # self.acc_rec_rx[entry]['ns'] = self.user_ns[entry]
- # for entry in self.user_ns_amo:
- # self.acc_rec_rx[entry]['ns_amo'] = self.user_ns_amo[entry]
- # TODO -> Попълваме сметките, по Ентрита на активи и амортизации
- if not self.dict_entries: # Речника е празен
- for entry in self.acc_rec_rx:
- self.acc_rec_rx[entry]['assets'].clear()
- # if not self.dict_entries_amo: # Речника е празен
- # for entry in self.acc_rec_rx:
- # self.acc_rec_rx[entry]['amort'].clear()
- for entry in self.dict_entries:
- if self.dict_entries[entry] is None:
- self.dict_entries[entry] = []
- self.acc_rec_rx[entry]['assets'] = self.dict_entries[entry]
- # for entry in self.dict_entries_amo:
- # if self.dict_entries_amo[entry] is None:
- # self.dict_entries_amo[entry] = []
- # self.acc_rec_rx[entry]['amort'] = self.dict_entries_amo[entry]
- # TODO -> попълване на сумите на преоценката
- # for entry in self.assets_re:
- # for dir in self.assets_re[entry]:
- # self.acc_rec_rx[entry]['assets_re'][dir] = self.assets_re[entry][dir]
- # for entry in self.amort_re:
- # for dir in self.amort_re[entry]:
- # self.acc_rec_rx[entry]['amort_re'][dir] = self.amort_re[entry][dir]
- # print('self.acc_rec_rx: ', self.acc_rec_rx)
- json_file_io = JsonFileIo(file_name=registry['orx_import_form_acc_rec_orx_file_name'])
- json_file_io.write_content(self.acc_rec_rx)
- # TODO -> Проверка за недобавена сметка и съобщение !!!!!
- if len(self.list_unadded_accs) > 0:
- # TODO -> Показва pop_message "Има недобавени сметки !
- pop_message = self.widget_factory.get_pop_message(self, lambda answer: self.set_pop_message_answer(answer),
- "Има недобавени сметки !", 1, 'red')
- self.wait_window(pop_message.pop)
- # TODO -> Ако "ДА"
- self.destroy()
- return
- else:
- pop_message = self.widget_factory.get_pop_message(self, lambda answer: self.set_pop_message_answer(answer),
- "Всички сметки са добавени !", 1, 'green')
- self.wait_window(pop_message.pop)
- # TODO -> Ако "ДА"
- self.destroy()
- return
- # def on_correction(self):
- # if self.b_note['state'] == 'disabled':
- # return
- # if self.current_tab == 'Активи':
- # # TODO -> Махаме маркировката на Treeview и забраната за селекция
- # for code in self.selected_accs:
- # self.treeview_acc.tag_configure(code, background='lightgrey')
- # self.selected_accs.clear()
- # # TODO -> Изтриваме стойностите на речника, на ентритата и лейбълите
- # self.dict_entries.clear()
- # self.get_total = {'total': {'od': 0.0, 'oc': 0.0, 'td': 0.0, 'tc': 0.0, 'cd': 0.0, 'cc': 0.0}}
- # self.l_open_adp['text'] = 0
- # self.l_open_pzp['text'] = 0
- # self.l_open_a['text'] = 0
- # self.l_open_pzas['text'] = 0
- # self.l_open_di['text'] = 0
- # self.l_open_drz['text'] = 0
- # self.l_open_isa['text'] = 0
- # # TODO -> На преоценките лейбъли ???
- # self.adp['text'] = 0
- # self.pzp['text'] = 0
- # self.a['text'] = 0
- # self.pzas['text'] = 0
- # self.di['text'] = 0
- # self.drz['text'] = 0
- # self.isa['text'] = 0
- # elif self.current_tab == 'Амортизации':
- # # TODO -> Махаме маркировката на Treeview и забраната за селекция
- # for code in self.selected_accs_amo:
- # self.treeview_acc.tag_configure(code, background='lightgrey')
- # self.selected_accs_amo.clear()
- # # TODO -> Изтриваме стойностите на речника, на ентритата и лейбълите
- # self.dict_entries_amo.clear()
- # self.get_total_amo = {'total': {'od': 0.0, 'oc': 0.0, 'td': 0.0, 'tc': 0.0, 'cd': 0.0, 'cc': 0.0}}
- # self.l_open_amo_di['text'] = 0
- # # TODO ?????
- # self.amo_di['text'] = 0
- #
- # self.fill_labels()
- #
- # self.fill_treeview(term_dc=self.term_dc)
- # TODO -> ЗА разлики между НС от потребителя и НС от сметките
- def update_state_open_bal(self, open_bal: Entry, key1: str, key2: str): # self.user_s, s, od
- name_entry = open_bal.winfo_name() # user_s
- print('name_entry: ', name_entry)
- user_1000 = open_bal.get() # 55
- try:
- user_1000 = int(user_1000)
- except:
- user_1000 = 0
- calc = self.get_sum_string(key1, key2) # s od
- calc_1000 = int(round(calc / 1000))
- if user_1000 == calc_1000:
- # TODO оцвети нещо
- open_bal.configure(bg='white')
- else:
- open_bal.configure(bg='red')
- # TODO -> Да се попълни речник с НС, въведени от потребителя !
- if self.current_tab == 'Разходи по вид':
- self.user_ns[key1] = user_1000
- elif self.current_tab == 'Амортизации':
- self.user_ns_amo[key1] = user_1000
- if name_entry == 'user_adp':
- self.adp['text'] = user_1000 - calc_1000
- print("self.acc_rec_rx", self.acc_rec_rx)
- self.acc_rec_rx['adp']['assets_re']['diff'] = user_1000 - calc_1000
- elif name_entry == 'user_pzp':
- self.pzp['text'] = int(user_1000 - calc_1000)
- self.acc_rec_rx['pzp']['assets_re']['diff'] = int(user_1000 - calc_1000)
- # elif name_entry == 'user_a':
- # self.a['text'] = int(user_1000 - calc_1000)
- # self.acc_rec_rx['a']['assets_re']['diff'] = int(user_1000 - calc_1000)
- elif name_entry == 'user_pzas':
- self.pzas['text'] = int(user_1000 - calc_1000)
- self.acc_rec_rx['pzas']['assets_re']['diff'] = int(user_1000 - calc_1000)
- elif name_entry == 'user_di':
- self.di['text'] = int(user_1000 - calc_1000)
- self.acc_rec_rx['di']['assets_re']['diff'] = int(user_1000 - calc_1000)
- elif name_entry == 'user_drz':
- self.drz['text'] = int(user_1000 - calc_1000)
- self.acc_rec_rx['drz']['assets_re']['diff'] = int(user_1000 - calc_1000)
- elif name_entry == 'user_isa':
- self.isa['text'] = int(user_1000 - calc_1000)
- self.acc_rec_rx['isa']['assets_re']['diff'] = int(user_1000 - calc_1000)
- elif name_entry == 'user_amo_di':
- self.amo_di['text'] = int(user_1000 - calc_1000)
- self.acc_rec_rx['di']['amort_re']['diff'] = int(user_1000 - calc_1000)
- def get_sum_string(self, key1, key2):
- if self.current_tab == 'Разходи по вид':
- if key1 in self.get_sums:
- return self.get_sums[key1][key2]
- elif self.current_tab == 'Амортизации':
- if key1 in self.get_sums_amo:
- return self.get_sums_amo[key1][key2]
- return 0
- def fill_labels(self):
- for entry in self.dict_entries_amo:
- if self.dict_entries_amo[entry] is None:
- self.dict_entries_amo[entry] = []
- for entry in self.dict_entries:
- if self.dict_entries[entry] is None:
- self.dict_entries[entry] = []
- if self.current_tab == 'Разходи по вид':
- if len(self.dict_entries) > 0:
- self.get_sums, self.get_total = self.mapped_calculations.get_sum_list_accounts(self.dict_entries)
- for entr in self.get_sums:
- if entr == 'adp':
- self.l_open_adp['text'] = f"{self.get_sums['adp']['td']:,.2f}".replace(',', ' ')
- self.update_state_open_bal(self.user_adp, "adp", "td")
- elif entr == 'pzp':
- self.l_open_pzp['text'] = f"{self.get_sums['pzp']['td']:,.2f}".replace(',', ' ')
- self.update_state_open_bal(self.user_pzp, "pzp", "td")
- elif entr == 'a':
- self.l_open_a['text'] = f"{self.get_sums['a']['td']:,.2f}".replace(',', ' ')
- self.update_state_open_bal(self.user_a, "a", "td")
- elif entr == 'pzas':
- self.l_open_pzas['text'] = f"{self.get_sums['pzas']['td']:,.2f}".replace(',', ' ')
- self.update_state_open_bal(self.user_pzas, "pzas", "td")
- elif entr == 'di':
- self.l_open_di['text'] = f"{self.get_sums['di']['td']:,.2f}".replace(',', ' ')
- self.update_state_open_bal(self.user_di, "di", "td")
- elif entr == 'drz':
- self.l_open_drz['text'] = f"{self.get_sums['drz']['td']:,.2f}".replace(',', ' ')
- self.update_state_open_bal(self.user_drz, "drz", "td")
- elif entr == 'isa':
- self.l_open_isa['text'] = f"{self.get_sums['isa']['td']:,.2f}".replace(',', ' ')
- self.update_state_open_bal(self.user_isa, "isa", "td")
- # self.l_open_total['text'] = f"{self.get_total['total']['od']:,.2f}".replace(',', ' ')
- self.l_turn_d_total['text'] = f"{self.get_total['total']['td']:,.2f}".replace(',', ' ')
- self.l_turn_c_total['text'] = f"{self.get_total['total']['tc']:,.2f}".replace(',', ' ')
- # self.l_close_total['text'] = f"{self.get_total['total']['cd']:,.2f}".replace(',', ' ')
- elif self.current_tab == 'Амортизации':
- if len(self.dict_entries_amo) > 0:
- self.get_sums_amo, self.get_total_amo =\
- self.mapped_calculations.get_sum_list_accounts(self.dict_entries_amo)
- for entr in self.get_sums_amo:
- if entr == 'di':
- self.l_open_amo_di['text'] = f"{self.get_sums_amo['di']['oc']:,.2f}".replace(',', ' ')
- self.update_state_open_bal(self.user_amo_di, "di", "oc")
- self.l_amo_open_total['text'] = f"{self.get_total_amo['total']['oc']:,.2f}".replace(',', ' ')
- self.l_amo_turn_d_total['text'] = f"{self.get_total_amo['total']['td']:,.2f}".replace(',', ' ')
- self.l_amo_turn_c_total['text'] = f"{self.get_total_amo['total']['tc']:,.2f}".replace(',', ' ')
- self.l_amo_close_total['text'] = f"{self.get_total_amo['total']['cc']:,.2f}".replace(',', ' ')
- def on_add(self):
- if self.current_tab == 'Разходи по вид':
- acc_code = self.last_entry.get() # '203'
- if acc_code is None or acc_code == '':
- return
- self.selected_accs.append(list(self.treeview_acc.selection())) # current_selection: ('200',)
- # TODO -> На името на Entry да добавим сметката
- name_entry = self.last_entry.winfo_name()
- if name_entry not in self.dict_entries:
- self.dict_entries[name_entry] = ()
- self.dict_entries[name_entry] += self.treeview_acc.selection() # Добавям маркираната сметка
- # TODO -> Добавяне на децата и родителите на добавената сметка
- all_children = self.account_tree.get_all_children(acc_code) # all_children: ['200', '203', '205']
- all_parents = self.account_tree.get_all_parents(acc_code) # acc_code = 223
- self.selected_accs.extend(all_children)
- self.selected_accs.extend(all_parents)
- # TODO -> След добавяне да се изпразват всички ентрита, а не само добавеното !!!!!
- if self.e_adp.get() != '': self.e_adp.delete(0, 'end')
- if self.e_pzp.get() != '': self.e_pzp.delete(0, 'end')
- if self.e_a.get() != '': self.e_a.delete(0, 'end')
- if self.e_pzas.get() != '': self.e_pzas.delete(0, 'end')
- if self.e_di.get() != '': self.e_di.delete(0, 'end')
- if self.e_drz.get() != '': self.e_drz.delete(0, 'end')
- if self.e_isa.get() != '': self.e_isa.delete(0, 'end')
- elif self.current_tab == 'Амортизации':
- acc_code = self.last_entry.get() # '203'
- if acc_code is None or acc_code == '':
- return
- self.selected_accs_amo.append(list(self.treeview_acc.selection()))
- # TODO -> На името на Entry да добавим сметката
- name_entry = self.last_entry.winfo_name()
- if name_entry not in self.dict_entries_amo:
- self.dict_entries_amo[name_entry] = ()
- self.dict_entries_amo[name_entry] += self.treeview_acc.selection()
- # TODO -> Добавяне на децата и родителите на добавената сметка
- all_children = self.account_tree.get_all_children(acc_code) # all_children: ['200', '203']
- all_parents = self.account_tree.get_all_parents(acc_code) # acc_code = 223
- self.selected_accs_amo.extend(all_children)
- self.selected_accs_amo.extend(all_parents)
- # TODO -> След добавяне да се изпразват всички ентрита, а не само добавеното !!!!!
- if self.e_amo_di.get() != '': self.e_amo_di.delete(0, 'end')
- self.fill_labels()
- # TODO -> Попълваме Treeview
- self.fill_treeview(term_dc=self.term_dc)
- def act_c1(self):
- if self.check_assets.get() == 1: # state: must be normal, disabled, or hidden
- self.tabs.tab(self.tab3, state='normal')
- # elif self.check_assets.get() == 0:
- # self.tabs.tab(self.tab3, state='hidden')
- def act_c2(self):
- if self.check_amort.get() == 1: # state: must be normal, disabled, or hidden
- self.tabs.tab(self.tab4, state='normal')
- # elif self.check_amort.get() == 0:
- # self.tabs.tab(self.tab4, state='hidden')
- def verify_selection(self): # Забрана за маркиране
- for code in self.selected_accs:
- if self.treeview_acc.exists(code):
- self.treeview_acc.selection_remove(code)
- for code in self.selected_accs_amo:
- if self.treeview_acc.exists(code):
- self.treeview_acc.selection_remove(code)
- def on_selected_acc(self, source_treeview):
- self.verify_selection()
- current_item = source_treeview.focus()
- if current_item in self.selected_accs or current_item in self.selected_accs_amo: # <class 'tuple'>
- return
- values = source_treeview.item(current_item)["values"]
- if not isinstance(values, list):
- return
- code = values[0]
- self.last_entry.delete(0, END)
- self.last_entry.insert(0, code)
- def entry_on_focus(self, entry):
- self.last_entry = entry
- def on_entry_key_release(self, entry):
- self.last_entry = entry
- entry_text = entry.get()
- if len(entry_text) < 2:
- self.fill_treeview(term_dc=self.term_dc)
- return
- term = entry_text
- self.fill_treeview(term=term, term_dc=self.term_dc)
- def orx(self):
- # try:
- # json_file_io = JsonFileIo(file_name=registry["orx_import_form_acc_rec_orx_file_name"])
- # tmp_acc_rec_rx = json_file_io.read_content()
- # if tmp_acc_rec_rx is not None:
- # self.acc_rec_rx = tmp_acc_rec_rx
- # self.refill_form()
- # self.get_tab() # Рефрешва таба, попълва self.current_tab
- # except:
- # pass
- # self.fill_treeview(term_dc=self.term_dc)
- self.mainloop()
- def refill_form(self):
- # TODO -> Попълваме Treeview с маркирани и забранени за селектиране сметки
- for entry in self.acc_rec_rx:
- self.dict_entries[entry] = self.acc_rec_rx[entry]['assets']
- for entry in self.acc_rec_rx:
- self.dict_entries_amo[entry] = self.acc_rec_rx[entry]['amort']
- # TODO -> Попълваме сметките, децата и родителите на сметките в self.selected_accs, self.selected_accs_amo
- for entry_name in self.dict_entries:
- for acc_code in self.dict_entries[entry_name]:
- if acc_code not in self.selected_accs:
- self.selected_accs.append(acc_code)
- all_children = self.account_tree.get_all_children(acc_code) # all_children:['200', '203'']
- all_parents = self.account_tree.get_all_parents(acc_code) # acc_code = 223 all_parents:['22',]
- self.selected_accs.extend([a for a in all_children if a not in self.selected_accs])
- self.selected_accs.extend([a for a in all_parents if a not in self.selected_accs])
- for entry_name in self.dict_entries_amo:
- for acc_code in self.dict_entries_amo[entry_name]:
- if acc_code not in self.selected_accs_amo:
- self.selected_accs_amo.append(acc_code)
- all_children = self.account_tree.get_all_children(acc_code) # all_children:['200', '203',]
- all_parents = self.account_tree.get_all_parents(acc_code)
- self.selected_accs_amo.extend([a for a in all_children if a not in self.selected_accs_amo])
- self.selected_accs_amo.extend([a for a in all_parents if a not in self.selected_accs_amo])
- # TODO -> Попълваме Ентритата с НС user_ns и user_ns_amo
- for entry_name in self.user_ns:
- self.user_ns[entry_name] = self.acc_rec_rx[entry_name]['ns']
- if self.user_ns['adp'] > 0:
- self.user_adp.insert(0, self.user_ns['adp'])
- if self.user_ns['pzp'] > 0:
- self.user_pzp.insert(0, self.user_ns['pzp'])
- if self.user_ns['adas'] > 0:
- self.user_a.insert(0, self.user_ns['a'])
- if self.user_ns['pzas'] > 0:
- self.user_pzas.insert(0, self.user_ns['pzas'])
- if self.user_ns['di'] > 0:
- self.user_di.insert(0, self.user_ns['di'])
- if self.user_ns['drz'] > 0:
- self.user_drz.insert(0, self.user_ns['drz'])
- if self.user_ns['isa'] > 0:
- self.user_isa.insert(0, self.user_ns['isa'])
- for entry_name in self.user_ns_amo:
- self.user_ns_amo[entry_name] = self.acc_rec_rx[entry_name]['ns_amo']
- if self.user_ns_amo['di'] > 0:
- self.user_amo_di.insert(0, self.user_ns_amo['di'])
- # TODO -> Попълваме Ентритата с Преоценките
- print('self.assets_re: ', self.assets_re)
- for entry in self.assets_re:
- for dir in self.assets_re[entry]:
- self.assets_re[entry][dir] = self.acc_rec_rx[entry]['assets_re'][dir]
- print('self.assets_re след refill: ', self.assets_re)
- if self.assets_re['adp']['inc'] > 0:
- self.turn_d_adp.insert(0, self.assets_re['adp']['inc'])
- if self.assets_re['adp']['dec'] > 0:
- self.turn_c_adp.insert(0, self.assets_re['adp']['dec'])
- if self.assets_re['pzp']['inc'] > 0:
- self.turn_d_pzp.insert(0, self.assets_re['pzp']['inc'])
- if self.assets_re['pzp']['dec'] > 0:
- self.turn_c_pzp.insert(0, self.assets_re['pzp']['dec'])
- if self.assets_re['adas']['inc'] > 0:
- self.turn_d_adas.insert(0, self.assets_re['adas']['inc'])
- if self.assets_re['adas']['dec'] > 0:
- self.turn_c_adas.insert(0, self.assets_re['adas']['dec'])
- if self.assets_re['pzas']['inc'] > 0:
- self.turn_d_pzas.insert(0, self.assets_re['pzas']['inc'])
- if self.assets_re['pzas']['dec'] > 0:
- self.turn_c_pzas.insert(0, self.assets_re['pzas']['dec'])
- if self.assets_re['di']['inc'] > 0:
- self.turn_d_di.insert(0, self.assets_re['di']['inc'])
- if self.assets_re['di']['dec'] > 0:
- self.turn_c_di.insert(0, self.assets_re['di']['dec'])
- if self.assets_re['drz']['inc'] > 0:
- self.turn_d_drz.insert(0, self.assets_re['drz']['inc'])
- if self.assets_re['drz']['dec'] > 0:
- self.turn_c_drz.insert(0, self.assets_re['drz']['dec'])
- if self.assets_re['isa']['inc'] > 0:
- self.turn_d_isa.insert(0, self.assets_re['isa']['inc'])
- if self.assets_re['isa']['dec'] > 0:
- self.turn_c_isa.insert(0, self.assets_re['isa']['dec'])
- for entry in self.amort_re:
- for dir in self.amort_re[entry]:
- self.amort_re[entry][dir] = self.acc_rec_rx[entry]['amort_re'][dir]
- print('self.amort_re след refill: ', self.amort_re)
- if self.amort_re['di']['inc'] > 0:
- self.turn_d_amo_di.insert(0, self.amort_re['di']['inc'])
- if self.amort_re['di']['dec'] > 0:
- self.turn_c_amo_di.insert(0, self.amort_re['di']['dec'])
- def fill_treeview(self, term=None, term_dc='debit'):
- self.treeview_acc.delete(*self.treeview_acc.get_children()) # Вградена функция за изтриване на Treeview
- # TODO -> Spinboxes
- self.unadded_spin = self.var_spin_1.get() # Взима стойността на спинбокса за недобавени
- spin_2 = int(self.var_spin_2.get())
- self.all_accounts.extend(self.selected_accs)
- self.all_accounts.extend(self.selected_accs_amo)
- self.list_unadded_accs = self.account_tree.get_unadded_acc(self.all_accounts, self.acc_data_mapped_da)
- count_rows = 0
- for acc_code in self.acc_data_bycode:
- if acc_code not in self.acc_data_mapped_da:
- continue
- if term_dc is not None and term_dc == 'debit':
- if self.acc_data_bycode[acc_code]['open_c'] > 0 or self.acc_data_bycode[acc_code]['close_c'] > 0:
- continue
- elif term_dc is not None and term_dc == 'credit':
- if self.acc_data_bycode[acc_code]['open_d'] > 0 or self.acc_data_bycode[acc_code]['close_d'] > 0:
- continue
- if term is not None: # Искаме само сметките дето кода им започва с term
- term_len = len(term)
- code_piece = self.acc_data_bycode[acc_code]['code'][0:term_len]
- # Ако сметката не започва с term
- if term != code_piece:
- continue # прескачаме тая сметка, не отговаря на търсеното
- # TODO -> Ако spin_1 = 'недобавени' -> извежда само недобавените сметки в ентритата
- if self.unadded_spin == 'недобавени':
- if acc_code not in self.list_unadded_accs:
- continue
- # TODO -> spin_2 type of spin_2: <class 'int'>
- groups_in_acc_code = re.findall('[0-9]+', acc_code) # Връща list със групите на сметката
- top_group = groups_in_acc_code[0]
- depth = self.account_tree.get_depth(acc_code)
- if len(top_group) > spin_2 or depth > spin_2:
- continue
- count_rows += 1
- row = [self.acc_data_bycode[acc_code]['code'],
- self.acc_data_bycode[acc_code]['name'],
- self.acc_data_bycode[acc_code][self.open],
- self.acc_data_bycode[acc_code]['str_turn_d'],
- self.acc_data_bycode[acc_code]['str_turn_c'],
- self.acc_data_bycode[acc_code][self.close]]
- tags = acc_code
- iid = acc_code
- self.treeview_acc.insert('', END, values=row, tags=tags, iid=iid) # ????
- self.treeview_acc.config(height=count_rows)
- if count_rows > 20:
- self.treeview_acc.configure(height=20)
- for code in self.selected_accs: # Оцветяване на добавените сметки
- if self.treeview_acc.exists(code):
- self.treeview_acc.tag_configure(code, background='powderblue')
- for code in self.selected_accs_amo: # Оцветяване на добавените сметки
- if self.treeview_acc.exists(code):
- self.treeview_acc.tag_configure(code, background='powderblue')
- if __name__ == '__main__':
- orx = Expenses()
- orx.orx()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement