-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAccounting.py
3734 lines (2969 loc) · 163 KB
/
Accounting.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# !/usr/bin/env python
# coding: utf-8
"""
Accounting program
Program written, interpreted and created by Gabriele Lo Cascio.
Contacts:
LinkedIn: https://www.linkedin.com/in/gabriele-locascio
GitHub: https://github.com/Gabro29
Fiverr: https://it.fiverr.com/gabro_29?up_rollout=true
YouTube: https://www.youtube.com/channel/UCkGvbGqYzDi3lfgtbQ_pngg
PayPal: https://www.paypal.com/paypalme/Gabro29
Instagram: https://www.instagram.com/ga8ro
Versions:
- Alpha version released on 09/12/2022
- Version 1.00 released on 01/15/2022
- Version 1.50 released on 03/20/2022
- Verison 3.00 released on 12/09/2022
Background:
This SoftWare was created in order to replace that of Francesco Paolo Lo Cascio which was provided courtesy
of his previous employer Enzo Gulizzi. It was a program written in MS-Dos, no longer supported by Win10
and therefore no longer in use. In addition, the convention of naming revenue has been maintained with 'HAVING'
and exits with "GIVING" to avoid misunderstandings from Lo Cascio Senior.
How it works:
The program consists of a main class called 'Cashier', due to the direct link with the concept of accounting,
to which nine other classes are added as a corollary (MenuP, Input, PrintStorage, PrintDay, PrintSingle,
EditValue, Reset, UndoLastImport, Trasmission) developed as you go along to the needs.
Cashier:
Main class that acts as a master container for the nine frames of which the software is composed,
although they can be added other frames and other classes according to various needs. Furthermore, has a menu
with three functions:
-File:
° For importing an Excel file.
-Options:
° Client List:
Editing the list of stored names;
° Print options:
Change the separator used for export of the txt file;
° Create Backup:
Create a local Backup in a specific folder.
-Help:
° Contact me:
Provides the manufacturer's email address;
° About:
Show a disclaimer for using SoftWare.
MenuP:
It is the main hub from which you can navigate to the others screenshots. And, vice versa, it can be
reached by each screen.
Input:
Screen of daily use, allows you to enter the entries (HAVING) and exits (GIVING) and it is possible to
carry out this procedure is done manually by filling in the appropriate fields either by importing an Excel
spreadsheet. Also, it is possible select the date of the entered data. Finally, every time an account is
entered and the total balance is updated and the one of the single account is shown in such a way as to correct
any errors before you even save your work.
PrintStorage:
Display the list of all the present accounts and the respective totals with the addition at the bottom of the
total balance sheet. It is also possible export the entire archive of accounts to txt or just
those having a particular prefix.
PrintDay:
Along the lines of PrintStorage, this class operates at same way. What it sets out to do is go back
over time, then by selecting a particular date it is possible to view the total balance for that day.
Very useful when looking for errors.
N.B:
See EditValue and Reset for further information.
PrintSingle:
This class is in charge of analyzing every single account in the following ways:
-List of relative movements;
-Bar chart by date of movements;
-Selective filtering of data by date range;
-Txt export of movements;
-Balance related to the account (Debit, Credit, ZERO).
EditValue:
As the name suggests, this class deals with the modification and removal of the data entered.
First you look for an account, and then you operate the desired
modification.
N.B:
It also works in combination with PrintDay, in fact in case you notice any errors in data entry
by clicking on the respective line you can switch to edit screen and repair the mistake made.
Finally, you can return to PrintDay and continue the review or to MenuP.
Reset:
Such a class is very minimalist and takes care of the removal of all those accounts whose difference
between HAVING and GIVING is zero.
N.B:
If the reset is done then the balance for some dates may change because they are being deleted some
of the accounts they have only at the time of removal a nil balance, but previously it was not.
UndoLastImport:
This screen searches in the dataset the most recently inserted data and allows you to remove them, maybe
just in case you make some mistake and want ;to postpone it immediately.
Transmission:
This class deals with the migration of an account having one name to another. In case you want to change
a series of entries in bulk. For example transfer at the end of the month the profit to an account previously
created. So much in the end you can always use the date or data analysis.
"""
# Adding Imports
from tkinter import font as tkfont
from ttkthemes import ThemedStyle
from tkinter import Label, NO, W, CENTER, Frame, Entry, Listbox, E, TclError, END, Toplevel, Tk, Menu, Button, \
LabelFrame, Scrollbar, Text, ttk, messagebox
from tkcalendar import DateEntry
from datetime import date
from datetime import datetime
from tkinter.filedialog import asksaveasfile, askopenfile
from pandas import read_csv, set_option, DataFrame, Series, concat, read_excel, to_datetime
from numpy import array, vstack
from math import fsum
from matplotlib.pyplot import figure, show, setp
from seaborn import set_style
from matplotlib import use
from os import getcwd
from shutil import copyfile
from threading import Thread
from smtplib import SMTP_SSL
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import email.mime.application
# Custom Name For File
bill_names_file = "bill_names.txt"
try:
txt = open(f"{bill_names_file}", "xt")
txt.close()
except FileExistsError:
pass
with open(f"{bill_names_file}", "r") as file:
bill_names = [line.rstrip() for line in file]
dataset_file = "dataframe.csv"
try:
my_csv = open(f"{dataset_file}", "xt")
my_csv.close()
with open(f"{dataset_file}", "w") as f:
f.write("Name,Description,Amount,Date")
except FileExistsError:
pass
global_data_in_out = read_csv(f"{dataset_file}", engine="c")
icon_app = "icon.ico"
# Adding Global Variables
set_option('precision', 2)
count_d = 0
count_a = 0
name_day = ""
desc_day = ""
give_day = 0
have_day = 0
date_day = ""
name_in_the_box = ''
data_in = list()
data_out = list()
date_on_excel_file = str()
starting = True
styles = "clearlooks"
class SecondWindow(Toplevel):
"""Templete class for TopLevel windows"""
def __init__(self, parent, title, geometry, propagate, b):
super().__init__(parent)
self.title(title)
self.geometry(geometry)
self.propagate(propagate)
self.resizable(0, 0)
self.iconbitmap(f"{icon_app}")
# Utility Functions
def info_app(self):
"""Terms and conditions"""
info_window = SecondWindow(self, "Info App", "720x140", False, (0, 0))
style = ThemedStyle(info_window)
style.theme_use(f"{styles}")
info_label = Label(info_window,
text="This program was created for personal purposes by Gabro.\n"
"Disclosure of this program is prohibited\n"
"unless specifically requested by the manufacturer.\n"
"See the 'Help' menu for more info.",
font=("Spectral", 15),
foreground="black")
info_label.pack(pady=10)
def contact_me(self):
"""Give mail address of productor"""
contact_window = SecondWindow(self, "Mail Contact", "300x100", False, (0, 0))
style = ThemedStyle(contact_window)
style.theme_use(f"{styles}")
label_contact = Text(contact_window, height=3, font=("Spectral", 15))
label_contact.insert(1.0,
" You can contact the producer\n by email at:\n gabri729@gmail.com")
label_contact.pack()
label_contact.configure(state="disabled")
def scandata():
"""Get current Date"""
Mesi = {"January": "Gennaio", "February": "Febbraio", "March": "Marzo", "April": "Aprile", "May": "Maggio",
"June": "Giugno", "July": "Luglio", "August": "Agosto", "September": "Settembre",
"October": "Ottobre",
"November": "Novembre", "December": "Dicembre"}
oggi = date.today()
mese = oggi.strftime("%B")
dat = (oggi.strftime("%d"), Mesi[mese], oggi.strftime("%Y"))
return dat
def send_mail():
"""Send csv file via mail"""
global dataset_file
porta = 465
password = "your_password"
smtp_server = "smtp.gmail.com"
sender_email = "your_email"
receiver_email = "your_email"
# html to include in the body section
giorno, mese, anno = scandata()
time = datetime.now()
current_time = time.strftime("%H:%M:%S")
html = f"""BackUp File {giorno}/{mese}/{anno} Ore {current_time}"""
# Creating message.
msg = MIMEMultipart('alternative')
msg['Subject'] = "BackUp"
msg['From'] = sender_email
msg['To'] = receiver_email
# The MIME types for text/html
HTML_Contents = MIMEText(html, 'html')
with open(f"{dataset_file}", "rb") as myfile:
attach = email.mime.application.MIMEApplication(myfile.read(), _subtype="csv")
attach.add_header('Content-Disposition', 'attachment', filename=f"{dataset_file}")
# Attachment and HTML to body message.
msg.attach(attach)
msg.attach(HTML_Contents)
try:
with SMTP_SSL(smtp_server, porta) as server:
server.login(sender_email, password)
server.sendmail(msg['From'], msg['To'], msg.as_string())
except Exception as e:
with open("exception.txt", "w") as file:
file.write(f"{e}")
# Main Class Cashier
class Cashier(Tk):
def __init__(self, *args, **kwargs):
Tk.__init__(self, *args, **kwargs)
self.title("Accounting program")
self.geometry(f"{800}x{670}+{100}+{70}")
self.propagate(True)
self.resizable(1, 1)
global icon_app
self.iconbitmap(f"{icon_app}")
self.title_font = tkfont.Font(family='Helvetica', size=18, weight="bold", slant="italic")
# Overlap frames and then raise each one per time
container = Frame(self)
container.pack(side="top", fill="both", expand=True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)
self.frames = {}
self.task(container)
@staticmethod
def on_start():
"""Backup dataset"""
global dataset_file
copyfile(f"{dataset_file}", fr"Backup\{dataset_file}")
def task(self, container):
"""Main function for loading"""
global starting
# Add Menu
self.menubar = Menu(self)
self.add_menu()
self.config(menu=self.menubar)
for F in (Input, PrintStorage, PrintDay, PrintSingle, EditValue,
Reset, UndoLastImport, Trasmission, MenuP):
page_name = F.__name__
frame = F(parent=container, controller=self)
self.frames[page_name] = frame
frame.grid(row=0, column=0, sticky="nsew")
self.show_frame("MenuP")
starting = False
try:
import pyi_splash
pyi_splash.close()
except ModuleNotFoundError:
pass
def show_frame(self, page_name):
"""Show frame by the given page name"""
global name_day
if page_name in ("PrintDay", "PrintSingle", "Trasmission"):
name_day = ""
self.geometry("900x670")
elif page_name == "EditValue":
self.geometry("900x670")
elif page_name in ("Reset", "UndoLastImport"):
self.geometry("800x200")
else:
self.geometry("800x670")
frame = self.frames[page_name]
frame.tkraise()
frame.event_generate("<<ShowFrame>>")
def add_menu(self):
"""Add menu on main window"""
filemenu = Menu(self.menubar, tearoff=0, font=("Lucinda Console", 10))
filemenu.add_command(label="Open...", command=lambda: Thread(target=self.open_file).start())
filemenu.add_separator()
filemenu.add_command(label="Exit", command=self.quit)
self.menubar.add_cascade(label="File", menu=filemenu)
optionmenu = Menu(self.menubar, tearoff=0, font=("Lucinda Console", 10))
optionmenu.add_command(label="Bill Name List", command=self.edit_bill_name_file)
optionmenu.add_separator()
optionmenu.add_command(label="Print Options", command=self.setting_stampa)
optionmenu.add_separator()
optionmenu.add_command(label="Do Backup", command=self.do_backup)
self.menubar.add_cascade(label="Options", menu=optionmenu)
helpmenu = Menu(self.menubar, tearoff=0, font=("Lucinda Console", 10))
helpmenu.add_command(label="Contact Me", command=lambda: contact_me(self))
helpmenu.add_separator()
helpmenu.add_command(label="About...", command=lambda: info_app(self))
self.menubar.add_cascade(label="Help", menu=helpmenu)
def setting_stampa(self):
"""Custom your txt file"""
print_window = SecondWindow(self, "Print Options", "800x308", False, (0, 0))
style = ThemedStyle(stampa_window)
style.theme_use(f"{styles}")
separator_title = Label(print_window, text="Separator", font=("Spectral", 15), foreground="black",
relief="ridge")
separator_title.place(relx=0.13, rely=0.06)
exstension = Label(print_window, text="Exstension", font=("Spectral", 15), foreground="black",
relief="ridge")
exstension.place(relx=0.59, rely=0.06)
# ComboBox sep
self.separator_selection = ttk.Combobox(print_window, values=["Underscore", "Line", "Dot", "Tabular"],
font=("Lucinda Console", 15), foreground="black", state="readonly")
self.separator_selection.place(relx=0.04, rely=0.15)
self.separator_selection.bind("<<ComboboxSelected>>", self.see_anteprima)
self.separator_dict = {"______": 0, "------": 1, "......": 2, " ": 3}
with open("frills.dat", "r") as file:
for line in file:
if line.split("=")[0] == "Separator":
my_separatore = line.split("=")[1][:-1]
elif line.split("=")[0] == "Exstension":
my_estensione = line.split("=")[1][:-1]
self.separator_selection.current(self.separator_dict[my_separatore])
# ComboBox ext
self.extension_selection = ttk.Combobox(print_window, values=["txt", "csv", "dat"],
font=("Lucinda Console", 15), foreground="black", state="readonly")
self.extension_selection.place(relx=0.5, rely=0.15)
self.extension_selection.bind("<<ComboboxSelected>>", self.see_anteprima)
self.extension_dict = {"txt": 0, "csv": 1, "dat": 2}
self.extension_selection.current(self.extension_dict[my_estensione])
preview = LabelFrame(print_window, text="Preview", font=("Times", 20),
foreground="black")
preview.place(height=100, width=750, relx=0.04, rely=0.3)
self.show_preview = Label(preview, font=("Lucinda Console", 25),
foreground="black")
self.show_preview.place(relx=0.05, rely=0.05)
self.sep_dict = {"Underscore": "______", "Line": "------", "Dot": "......", "Tabular": " "}
self.show_preview.config(text=f"Name{self.sep_dict[self.separator_selection.get()]}Amount")
save_button = Button(print_window, text="Save",
fg="black", bg="sandy brown", relief="raised",
activebackground="light gray", font=("Lucinda Console", 20))
save_button.place(relx=0.42, rely=0.75)
def do_backup(self):
"""Open Popup and do backup"""
self.on_start()
messagebox.showinfo("Copy of File", "Backup done in directory 'Backup'")
def open_file(self):
"""Open Excel file on Input screen"""
global data_in
global data_out
global date_on_excel_file
error_entrate = [False, None]
error_uscite = [False, None]
open_xls = askopenfile(initialdir=getcwd(), title="Import Excel File",
mode="r", filetypes=[("Excel File", ".xls"), ("Excel File", ".xlsx")])
if open_xls is not None:
data_cashier = read_excel(open_xls.name)
raw_date_time = (str(data_cashier[data_cashier.columns[0]][0]).split(" ")[0]).split("-")
try:
date_on_excel_file = f"{raw_date_time[2]}-{raw_date_time[1]}-{raw_date_time[0]}"
except IndexError:
date_on_excel_file = None
for index, col in enumerate(data_cashier.columns):
if index < 6:
data_cashier.drop(index, inplace=True)
if index >= 4:
data_cashier.drop(col, axis=1, inplace=True)
data_cashier.columns = ["Nomi_Entrate", "Importo_Entrate", "Nomi_Uscite", "Importo_Uscite"]
# Entrate
for major_index in range(6, data_cashier.Nomi_Entrate.size):
if f"{data_cashier.Nomi_Entrate[major_index]}" != "nan":
try:
desc = str(data_cashier.Nomi_Entrate[major_index]).split("(")[1].replace(")", "")
except IndexError:
desc = ''
raff_name = ''
for letter in str(data_cashier.Nomi_Entrate[major_index]).split("(")[0].split(' '):
if letter != '':
raff_name += letter + ' '
raff_name = (raff_name[:-1]).upper()
raff_desc = ''
for letter in desc.split(' '):
if letter != '':
raff_desc += letter + ' '
raff_desc = (raff_desc[:-1])
try:
float(data_cashier.Importo_Entrate[major_index])
except Exception:
error_entrate[0] = True
error_entrate[1] = major_index + 8
else:
if str(data_cashier.Importo_Entrate[major_index]) != 'nan':
data_in.append([raff_name, raff_desc, float(data_cashier.Importo_Entrate[major_index])])
if "," in str(raff_name):
error_entrate[0] = True
error_entrate[1] = major_index + 8
# Uscite
for major_index in range(6, data_cashier.Nomi_Uscite.size):
desc = ''
if f"{data_cashier.Nomi_Uscite[major_index]}" != "nan":
try:
desc = str(data_cashier.Nomi_Uscite[major_index]).split("(")[1].replace(")", "")
except IndexError:
desc = ''
raff_name = ''
for letter in str(data_cashier.Nomi_Uscite[major_index]).split("(")[0].split(' '):
if letter != '':
raff_name += letter + ' '
raff_name = (raff_name[:-1]).upper()
raff_desc = ''
for letter in desc.split(' '):
if letter != '':
raff_desc += letter + ' '
raff_desc = (raff_desc[:-1])
try:
float(data_cashier.Importo_Uscite[major_index])
except Exception:
error_uscite[0] = True
error_uscite[1] = major_index + 8
else:
if str(data_cashier.Importo_Uscite[major_index]) != 'nan':
data_out.append([raff_name, raff_desc, float(data_cashier.Importo_Uscite[major_index])])
if "," in str(raff_name):
error_uscite[0] = True
error_uscite[1] = major_index + 8
if error_entrate[0]:
messagebox.showerror("Attenzione", "Controllare il File da importare!\n"
f"Errore nella colonna dell' AVERE\n"
f"alla linea {error_entrate[1]}")
elif error_uscite[0]:
messagebox.showerror("Attenzione", "Controllare il File da importare!\n"
f"Errore nella colonna del DARE\n"
f"alla linea {error_uscite[1]}")
elif not error_entrate[0] and not error_uscite[0]:
self.show_frame("Input")
def edit_bill_name_file(self):
"""Edit bill_name_file window"""
edit_file_window = SecondWindow(self, "Edit Bill Name File", "480x720", False, (0, 0))
style = ThemedStyle(edit_file_window)
style.theme_use(f"{styles}")
title_label = Label(edit_file_window, text="Remove single bill name "
"or entire file", font=("Spectral", 15),
foreground="black", relief="ridge")
title_label.pack(side="top", fill="x", pady=10)
tree_style = ttk.Style()
tree_style.configure("mystyle.Treeview.Heading",
font=('Spectral', 18, 'italic')) # Modify the font of the headings
tree_style.layout("mystyle.Treeview",
[('mystyle.Treeview.treearea', {'sticky': 'nswe'})]) # Remove the borders
tree_style.configure('Treeview', rowheight=40)
self.tree = ttk.Treeview(edit_file_window, style="mystyle.Treeview", selectmode="extended")
self.tree["columns"] = "Nome"
self.tree.column("#0", width=0, stretch=NO)
self.tree.column("Nome", anchor=W, width=250)
self.tree.heading("#0", text="", anchor=CENTER)
self.tree.heading("Nome", text="Nome", anchor=W)
# Create a list of all the menu items
global bill_names
for count, record in enumerate(bill_names):
self.tree.insert(parent="", index="end", iid=count, text="", values=(record,))
tree_scrolly = Scrollbar(edit_file_window, orient="vertical", command=self.tree.yview)
self.tree.configure(yscrollcommand=tree_scrolly.set)
tree_scrolly.pack(side="right", fill="y")
self.tree.pack()
rm_sel = Button(edit_file_window, text="Remove selected", command=self.rmp_from_file,
fg="black", bg="Silver", relief="raised",
activebackground="light gray", font=("Times", 15), pady=10)
rm_sel.place(relx=0.27, rely=0.71, width=200, height=30)
rm_all = Button(edit_file_window, text="Remove All", command=self.rmall_from_file,
fg="black", bg="sandy brown", relief="raised",
activebackground="light gray", font=("Times", 10), pady=30)
rm_all.place(relx=0.35, rely=0.81, width=120, height=30)
def rmp_from_file(self):
"""Remove person in tree"""
global bill_names
selected = self.tree.focus()
selected = self.tree.item(selected)
bill_names.remove(selected["values"][0])
selected = self.tree.selection()
self.tree.delete(int(str(selected).split("(")[1][1]))
with open(f"{bill_names}", "w") as file:
for c in bill_names:
file.write(f"{c}\n")
def rmall_from_file(self):
"""Clean up txt file and tree view"""
with open(f"{bill_names}", "w") as file:
pass
for child in self.tree.get_children():
self.tree.delete(child)
def see_anteprima(self, sel):
"""See preview"""
if self.extension_selection.get() == "csv":
self.separator_selection.config(state="disable")
self.show_anteprima.config(text="Name,Amount")
else:
self.separator_selection.config(state="readonly")
self.show_anteprima.config(text=f"Name{self.sep_dict[self.separator_selection.get()]}Amount")
with open("frills.dat", "w") as file:
file.write(f"Separator={self.sep_dict[self.separator_selection.get()]}\n")
file.write(f"Exstension={self.extension_selection.get()}\n")
file.write("Dir=")
# Main Menu
class MenuP(Frame):
def __init__(self, parent, controller):
Frame.__init__(self, parent)
self.style = ThemedStyle(self)
self.style.theme_use(f"{styles}")
self.controller = controller
self.menu_selection = LabelFrame(self, text="Main Menu", font=("Times", 15),
foreground="black")
self.menu_selection.place(height=600, width=650, relx=0.03, rely=0.03)
input_button = Button(self.menu_selection, text="Input", bg="silver", relief="raised",
font=("Spectral", 15), command=lambda: controller.show_frame("Input"),
activebackground="sandy brown")
print_button = Button(self.menu_selection, text="Archive Print", bg="silver", relief="raised",
font=("Spectral", 15), command=lambda: controller.show_frame("PrintStorage"),
activebackground="sandy brown")
print_day_button = Button(self.menu_selection, text="Print Inputs Of The Day",
bg="silver", relief="raised", font=("Spectral", 15),
command=lambda: controller.show_frame("PrintDay"),
activebackground="sandy brown")
print_single_button = Button(self.menu_selection, text="Print Single Bill Name", bg="silver", relief="raised",
font=("Spectral", 15), command=lambda: controller.show_frame("PrintSingle"),
activebackground="sandy brown")
edit_button = Button(self.menu_selection, text="Edit Values", bg="silver", relief="raised",
font=("Spectral", 15), command=lambda: controller.show_frame("EditValue"),
activebackground="sandy brown")
reset_button = Button(self.menu_selection, text="Reset", bg="silver", relief="raised",
font=("Spectral", 15), command=lambda: controller.show_frame("Reset"),
activebackground="sandy brown")
undo_button = Button(self.menu_selection, text="Undo Last Import", bg="silver", relief="raised",
font=("Spectral", 15), command=lambda: controller.show_frame("UndoLastImport"),
activebackground="sandy brown")
trasmissione_button = Button(self.menu_selection, text="Trasmission", bg="silver",
relief="raised",
font=("Spectral", 15), command=lambda: controller.show_frame("Trasmission"),
activebackground="sandy brown")
input_button.place(height=30, width=500, relx=0.1, rely=0.1)
print_button.place(height=30, width=500, relx=0.1, rely=0.2)
print_day_button.place(height=30, width=500, relx=0.1, rely=0.3)
print_single_button.place(height=30, width=500, relx=0.1, rely=0.4)
edit_button.place(height=30, width=500, relx=0.1, rely=0.5)
reset_button.place(height=30, width=500, relx=0.1, rely=0.6)
undo_button.place(height=30, width=500, relx=0.1, rely=0.7)
trasmissione_button.place(height=30, width=500, relx=0.1, rely=0.8)
try:
Thread(target=send_mail).start()
except Exception as e:
with open("exception.txt", "w") as file:
file.write(f"{e}")
# Input Screen
class Input(Frame):
def __init__(self, parent, controller):
Frame.__init__(self, parent)
self.style = ThemedStyle(self)
self.style.theme_use(f"{styles}")
self.controller = controller
label = Label(self, text="Input", font=("Spectral", 15), foreground="black", relief="ridge")
label.pack(side="top", fill="x", pady=10)
button = Button(self, text="Back to main menu", command=lambda: self.back_to_menu(controller),
fg="black", bg="sandy brown", relief="raised",
activebackground="light gray", font=("Lucinda Console", 10))
button.pack()
self.container = LabelFrame(self)
self.container.place(height=308, width=720, relx=0.05, rely=0.13)
self.in_out_tabs = ttk.Notebook(self.container)
self.mesi_ordine = {"Gennaio": 1, "Febbraio": 2, "Marzo": 3, "Aprile": 4, "Maggio": 5, "Giugno": 6,
"Luglio": 7, "Agosto": 8, "Settembre": 9, "Ottobre": 10, "Novembre": 11, "Dicembre": 12}
# Create Frames
self.give_to_me_tab = Frame(self.in_out_tabs, width=740, height=308) # , bg="#d9ead3")
self.give_to_you_tab = Frame(self.in_out_tabs, width=740, height=308) # , bg="#d5c6d7")
self.in_out_tabs.add(self.give_to_me_tab, text="GIVING (E)")
self.in_out_tabs.add(self.give_to_you_tab, text="HAVING (I)")
self.in_out_tabs.place(relx=0, rely=0)
self.in_out_tabs.bind("<<NotebookTabChanged>>", lambda x: self.change_tab_color(x))
self.style_tab = ttk.Style()
self.style_tab.map('TNotebook.Tab', background=[('selected', 'red'), ('active', 'lightgreen')])
# Insert tree in tab
self.tree_have()
self.tree_give()
# Create the Entries
self.name_entry = Entry(self, font=("Lucinda Console", 15))
self.name_entry.place(relx=0.05, rely=0.6, width=160, height=30)
self.name_entry.bind('<KeyRelease>', self.see_balance)
self.description_entry = Entry(self, font=("Lucinda Console", 15))
self.description_entry.place(relx=0.28, rely=0.6, width=250, height=30)
self.amount_entry = Entry(self, font=("Lucinda Console", 15))
self.amount_entry.place(relx=0.62, rely=0.6, width=110, height=30)
# Create a Listbox widget to display the list of items
self.suggestion = Listbox(self, font=("Lucinda Console", 15), relief="flat")
self.suggestion.place(relx=0.05, rely=0.64, width=160, height=100)
self.suggestion.bind("<Double-Button-1>", self.select_suggestion)
self.suggestion.bind("<Return>", self.select_suggestion)
global bill_names
# Add values to combobox
self.update_suggestion_list(bill_names)
# Add buttons
add_button = Button(self, text="Add", command=lambda: Thread(target=self.add_person).start(),
fg="black", bg="Silver", relief="raised",
activebackground="light gray", font=("Times", 15))
add_button.place(relx=0.8, rely=0.6, width=110, height=30)
add_button.bind("<Return>", self.enter_add_button)
clear_button = Button(self, text="Clear", command=self.clear_boxes,
fg="black", bg="light gray", relief="raised",
activebackground="#d9ead3", font=("Times", 15))
clear_button.place(relx=0.5, rely=0.7, width=110, height=30)
remove_button = Button(self, text="Remove", command=self.remove_person,
fg="black", bg="sandy brown", relief="raised",
activebackground="light gray", font=("Times", 15))
remove_button.place(relx=0.68, rely=0.7, width=110, height=30)
edit_button = Button(self, text="Edit", command=self.edit_person,
fg="black", bg="wheat1", relief="raised",
activebackground="light gray", font=("Times", 15))
edit_button.place(relx=0.85, rely=0.7, width=110, height=30)
undo_import = Button(self, text="Undo\nImport", command=self.undo,
fg="black", bg="#a8bed0", relief="raised",
activebackground="Silver", font=("Times", 12))
undo_import.place(relx=0.3, rely=0.7, width=110, height=40)
self.on_start()
self.bind("<<ShowFrame>>", self.on_show_frame)
def on_show_frame(self, event):
"""ON Raise"""
global data_in
global data_out
global count_d
global count_a
global starting
global bill_names
global bill_names_file
global global_data_in_out
global date_on_excel_file
global dataset_file
if not starting:
global_data_in_out = read_csv(f"{dataset_file}", engine="c")
if len(data_in) != 0 or len(data_out) != 0:
for i_exit in range(len(data_out)):
name = str(data_out[i_exit][0])
raff_name = ''
for letter in name.split(' '):
if letter != '':
raff_name += letter + ' '
if (raff_name[:-1]).upper() not in bill_names:
bill_names.append(name)
bill_names.sort()
with open(f"{bill_names_file}", "w") as file:
for c in bill_names:
file.write(f"{c.upper()}\n")
if count_d % 2 == 0:
self.tree_give_tme.insert(parent="", index="end", iid=count_d, text="",
values=data_out[i_exit],
tags=("evenrow",))
else:
self.tree_give_tme.insert(parent="", index="end", iid=count_d, text="",
values=data_out[i_exit],
tags=("oddrow",))
count_d += 1
for i_entry in range(len(data_in)):
name = str(data_in[i_entry][0])
raff_name = ''
for letter in name.split(' '):
if letter != '':
raff_name += letter + ' '
if (raff_name[:-1]).upper() not in bill_names:
bill_names.append(name)
bill_names.sort()
with open(f"{bill_names_file}", "w") as file:
for c in bill_names:
file.write(f"{c.upper()}\n")
if count_a % 2 == 0:
self.tree_give_tyou.insert(parent="", index="end", iid=count_a, text="",
values=data_in[i_entry],
tags=("evenrow",))
else:
self.tree_give_tyou.insert(parent="", index="end", iid=count_a, text="",
values=data_in[i_entry],
tags=("oddrow",))
count_a += 1
self.diff_totali()
self.date_entry.destroy()
# Check if the Date is spoecified in Excel file
if date_on_excel_file is None:
giorno, mese, anno = scandata()
date_on_excel_file = f"{giorno}-{self.mesi_ordine[mese]}-{anno}"
raff_month = self.mesi_ordine[mese]
elif str(date_on_excel_file.split("-")[1])[0] == "0":
raff_month = str(date_on_excel_file.split("-")[1])[1:]
else:
raff_month = date_on_excel_file.split("-")[1]
self.date_entry = DateEntry(self, selectmode="day", font="Lucinda 10", locale="it_IT",
showweeknumbers=False,
showothermonthdays=True,
year=int(date_on_excel_file.split("-")[2]),
month=int(raff_month),
day=int(date_on_excel_file.split("-")[0]),
background="dark slate gray", date_pattern="DD/MM/YYYY",
bordercolor="dark slate gray", selectbackground="SlateGray4",
headersbackground="light gray", normalbackground="light gray",
foreground='white',
normalforeground='black', headersforeground='black',
weekendbackground="IndianRed1")
self.date_entry.place(relx=0.81, rely=0.09)
self.date_entry.bind("<<DateEntrySelected>>", self.select_data)
else:
self.diff_totali()
self.clear_boxes()
self.name_entry.focus()
def on_start(self):
"""Build Frame"""
# Let user select the day
giorno, mese, anno = scandata()
self.date_entry = DateEntry(self, selectmode="day", font="Lucinda 10", locale="it_IT", showweeknumbers=False,
showothermonthdays=True,
year=int(anno), month=self.mesi_ordine[mese], day=int(giorno),
background="dark slate gray", date_pattern="DD/MM/YYYY",
bordercolor="dark slate gray", selectbackground="SlateGray4",
headersbackground="light gray", normalbackground="light gray", foreground='white',
normalforeground='black', headersforeground='black', weekendbackground="IndianRed1")
self.date_entry.place(relx=0.81, rely=0.09)
self.date_entry.bind("<<DateEntrySelected>>", self.select_data)
self.today = True
# See stored bill
live_attributes_d = Label(self, text="GIVING (E)", font=("Spectral", 15), foreground="black", relief="ridge")
live_attributes_d.place(relx=0.01, rely=0.81, width=110, height=30)
live_attributes_a = Label(self, text="HAVING (I)", font=("Spectral", 15), foreground="black", relief="ridge")
live_attributes_a.place(relx=0.01, rely=0.86, width=110, height=30)
self.live_attributes_t = Label(self, text="BALANCE", font=("Spectral", 11), foreground="black", relief="ridge")
self.live_attributes_t.place(relx=0.01, rely=0.915, width=110, height=40)
self.give_live_label = Label(self, font=("Spectral", 15), foreground="black", relief="ridge")
self.give_live_label.place(relx=0.15, rely=0.81, width=130, height=30)
self.have_live_label = Label(self, font=("Spectral", 15), foreground="black", relief="ridge")
self.have_live_label.place(relx=0.15, rely=0.86, width=130, height=30)
self.balance_live_label = Label(self, font=("Spectral", 15), foreground="black", relief="ridge")
self.balance_live_label.place(relx=0.15, rely=0.915, width=130, height=40)
tot_label = Label(self, text="Total", font=("Spectral", 18), foreground="black", relief="ridge")
tot_label.config(anchor=CENTER)
tot_label.place(height=38, width=100, relx=0.46, rely=0.835)
self.give_label = Label(self, text="", font=("Spectral", 15),
foreground="black",
relief="ridge")
self.give_label.config(anchor=CENTER)
self.give_label.place(height=38, width=150, relx=0.6, rely=0.835)
self.have_label = Label(self, text="", font=("Spectral", 15),
foreground="black",
relief="ridge")
self.have_label.config(anchor=CENTER)
self.have_label.place(height=38, width=150, relx=0.79, rely=0.835)
self.diff_label = Label(self, text="",
font=("Spectral", 15),
foreground="black", relief="ridge")
self.diff_label.config(anchor=CENTER)
self.diff_label.place(height=40, width=150, relx=0.69, rely=0.90)
self.diff_label_t = Label(self, text="Difference", font=("Spectral", 18), foreground="black", relief="ridge")
self.diff_label_t.config(anchor=CENTER)
self.diff_label_t.place(height=40, width=150, relx=0.46, rely=0.90)
self.suggestion.bind("<Tab>", self.see_balance)
def change_tab_color(self, color):
"""Change color of the tab"""
if self.in_out_tabs.index("current") == 1:
self.name_entry.focus()
self.style_tab = ttk.Style()
self.style_tab.map('TNotebook.Tab', background=[('selected', 'lightgreen'), ('active', 'red')])
elif self.in_out_tabs.index("current") == 0:
self.name_entry.focus()
self.style_tab = ttk.Style()
self.style_tab.map('TNotebook.Tab', background=[('selected', 'red'), ('active', 'lightgreen')])
def tree_give(self):
"""Add GIVING Tree in tab"""
tree_style = ttk.Style()
tree_style.configure("mystyle.Treeview", highlightthickness=0, bd=0,
font=('Lucinda Console', 16)) # Modify the font of the body
tree_style.configure("mystyle.Treeview.Heading",
font=('Spectral', 18, 'italic'), width=1, pady=20) # Modify the font of the headings
tree_style.layout("mystyle.Treeview", [('mystyle.Treeview.treearea', {'sticky': 'nswe'})]) # Remove the borders
tree_style.configure('Treeview', rowheight=40)
self.tree_give_tme = ttk.Treeview(self.give_to_me_tab, style="mystyle.Treeview", selectmode="extended")
self.tree_give_tme["columns"] = ("Name", "Description", "Amount")
self.tree_give_tme.column("#0", width=0, stretch=NO)
self.tree_give_tme.column("Name", anchor=W, width=250, stretch=NO)
self.tree_give_tme.column("Description", anchor=CENTER, width=280, stretch=NO)
self.tree_give_tme.column("Amount", anchor=E, width=145, stretch=NO)
self.tree_give_tme.heading("#0", text="", anchor=CENTER)
self.tree_give_tme.heading("Name", text="Name", anchor=W)
self.tree_give_tme.heading("Description", text="Description", anchor=CENTER)
self.tree_give_tme.heading("Amount", text="Amount", anchor=E)
self.tree_give_tme.tag_configure("oddrow", background="white")
self.tree_give_tme.tag_configure("evenrow", background="IndianRed3")
global count_d
count_d = 0
for record in []:
if count_d % 2 == 0:
self.tree_give_tme.insert(parent="", index="end", iid=count_d, text="", values=record,
tags=("evenrow",))
else:
self.tree_give_tme.insert(parent="", index="end", iid=count_d, text="", values=record, tags=("oddrow",))