-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·171 lines (155 loc) · 5.76 KB
/
main.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
import tkinter as tk
from tkinter import ttk
from tkinter import messagebox
from tkinter import simpledialog
import pdb
import googleData
import datetime
from scrollableFrame import ScrollableFrame
items = []
dfsPerBrand = googleData.loadData()
def _search():
itemNo = searchText.get( "1.0", "end" ).replace( '\n', '' )
options = []
for brand, dfs in dfsPerBrand.items():
for orderNo, df in enumerate( dfs ):
idxs = df.loc[ df['ItemNo'] == itemNo ].index.values.astype( int )
if( len( idxs ) > 0 ):
for idx in idxs:
idx = df.loc[ df['ItemNo'] == itemNo ].index.values.astype( int )[ 0 ]
qtyLeft = df.loc[ idx, 'QtyLeft' ]
if qtyLeft != '0':
option = {}
option[ 'Brand' ] = brand
option[ 'Sheet' ] = 'ORDER%d!' % ( orderNo + 1 )
option[ 'IdxInSheet' ] = idx + 2
option[ 'ItemNo' ] = itemNo
option[ 'ItemDesc' ] = df.loc[ idx, 'ItemDesc' ]
option[ 'Price' ] = df.loc[ idx, 'Price' ]
option[ 'QtyLeft' ] = df.loc[ idx, 'QtyLeft' ]
option[ 'CostPrice' ] = df.loc[ idx, 'CostPrice' ]
sellingPrice = float( option[ 'Price' ] )
costPrice = float( option[ 'CostPrice' ] )
maxDiscount = ( ( sellingPrice - costPrice ) / sellingPrice ) * 100.0
option[ 'Text' ] = '%s---%s---Brand:%s---Order:%s---Price:%s---MaxDiscount:%s' \
% ( option[ 'ItemNo' ], option[ 'ItemDesc' ], option[ 'Brand' ],
option[ 'Sheet' ], option[ 'Price' ], str( maxDiscount ) )
options.append( option )
return options
def search():
options = _search()
if( len( options ) == 0 ):
notFoundItem = []
notFoundItem.append( searchText.get( "1.0", "end" ).replace( '\n', '' ) )
notFoundItem.append( getDate() )
googleData.writeNotFoundItem( notFoundItem )
display = 'Item Not In Stock'
result = 'Failure'
messagebox.showinfo( result, display )
return
if( len( options ) > 1 ):
optionsText = ""
for i, option in enumerate( options ):
optionsText += "%d) %s\n" % ( i, option[ 'Text' ] )
choice = simpledialog.askinteger( "Options", optionsText )
item = options[ choice ]
else:
item = options[ 0 ]
# Item Index in the Current Bill
item[ 'Idx' ] = len( items )
# Label to display
item[ 'LabelEl' ] = tk.Label( listFrame, text=item[ 'Text' ] )
item[ 'LabelEl' ].grid( row=item[ 'Idx' ] )
# Item Quantity selection box
item[ 'QtyBox' ] = tk.Spinbox( listFrame, from_=0, to=100 )
item[ 'QtyBox' ].grid( row=item[ 'Idx' ], column=1 )
item[ 'QtyBox' ].invoke( "buttonup" )
# Item Discount selection box
item[ 'DiscountBox' ] = tk.Spinbox( listFrame, from_=0, to=100 )
item[ 'DiscountBox' ].grid( row=item[ 'Idx' ], column=2 )
items.append( item )
def getTotal( finalItems ):
total = 0.0
for item in finalItems:
price = float( item[ 'Price' ] )
discount = price * ( int( item[ 'Discount' ] ) / 100 )
total += ( price - discount ) * item[ 'Qty' ]
return total
def getDate():
currentDate = datetime.datetime.now()
return currentDate.strftime("%x")
def bill():
finalItems = []
billText = ""
for item in items:
item[ 'Qty' ] = min( int( item[ 'QtyBox' ].get() ), float( item[ 'QtyLeft' ] ) )
item[ 'Discount' ] = item[ 'DiscountBox' ].get()
if item[ 'Qty' ] > 0:
item[ 'Text' ] = item[ 'Text' ] + '---Qty:%s---Dis:%s' % ( str( item[ 'Qty' ] ), item[ 'Discount' ] )
finalItems.append( item )
billText = billText + item[ 'Text' ] + "\n"
if len( finalItems ) > 0:
confirm = messagebox.askokcancel( "Confirm Bill", billText )
if confirm:
bill = {
'Id' : googleData.getMaxBillID() + 1,
'Customer' : customerText.get( "1.0", "end" ).replace( '\n', '' ),
'Date' : getDate(),
'Items' : finalItems,
'Total' : getTotal( finalItems ),
}
googleData.writeBill( bill )
# Open a sheet with bill that can be printed ( See what TODO )
else:
# Don't do anything, might want to edit the order
return
else:
messagebox.showinfo( "Not Available", "Please select some availabe items" )
# Load the data from the sheets again for safety
global dfsPerBrand
dfsPerBrand = googleData.loadData()
# Clear local state
clear()
def clear():
global listFrameTop, listFrame
listFrameTop.destroy()
listFrameTop = ScrollableFrame( root )
listFrameTop.place( rely=searchAreaHeight, relheight=listAreaHeight, relwidth=1 )
listFrame = listFrameTop.scrollable_frame
items.clear()
# Start of all the widgets
root = tk.Tk()
# Setup
searchAreaHeight = 0.05
listAreaHeight = 0.9
billAreaHeight = 0.05
# Canvas
canvas = tk.Canvas( root, height=700, width=1200, bg='#FFFFFF' )
canvas.pack()
# Search Frame
searchFrame = tk.Frame( root, bg="#008000" )
searchFrame.place( relheight=searchAreaHeight, relwidth=1 )
searchTextWidth = 0.4
customerTextWidth = 0.4
searchButtonWidth = 1 - searchTextWidth - customerTextWidth
searchText = tk.Text( searchFrame )
searchText.place( relheight=1, relwidth=searchTextWidth )
searchText.insert( tk.END, "ItemNo...")
customerText = tk.Text( searchFrame, bg="#b3ffff")
customerText.place( relx=searchTextWidth, relheight=1, relwidth=customerTextWidth )
customerText.insert( tk.END, "Customer...")
searchButton = ttk.Button( searchFrame, text="Search", command=search )
searchButton.place( relx=1-searchButtonWidth, relheight=1, relwidth=searchButtonWidth )
# List Frame
listFrameTop = ScrollableFrame( root )
listFrameTop.place( rely=searchAreaHeight, relheight=listAreaHeight, relwidth=1 )
listFrame = listFrameTop.scrollable_frame
# Bill Frame
billFrame = tk.Frame( root, bg="#B0B0B0" )
billFrame.place( rely=searchAreaHeight+listAreaHeight, relheight=billAreaHeight, relwidth=1 )
billButton = ttk.Button( billFrame, text="Bill", command=bill )
billButton.place( relheight=1, relwidth=0.5 )
clearButton = ttk.Button( billFrame, text="Clear", command=clear )
clearButton.place( relx=0.5, relheight=1, relwidth=0.5 )
# End of all the widgets
root.mainloop()