-
Notifications
You must be signed in to change notification settings - Fork 60
/
invoiceInfoPanel.py
127 lines (103 loc) · 4.12 KB
/
invoiceInfoPanel.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
# 26th May, 2018 5:05pm
import wx
import wx.grid
import wx.xrc
import wx.dataview
from connectToDb import connectToDB
import updateInvoiceMoney as uim
class invoiceInfoPanel ( wx.Panel ):
def __init__( self, parent ):
wx.Panel.__init__( self, parent, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )
bSizer11 = wx.BoxSizer( wx.VERTICAL )
self.m_invoiceGrid = wx.grid.Grid( self, wx.ID_ANY, wx.DefaultPosition, wx.Size( -1,700 ), 0 )
p = self.populateTable()
lenP = len(p)
# Grid
self.m_invoiceGrid.CreateGrid( lenP, 10 )
self.m_invoiceGrid.EnableEditing( False )
self.m_invoiceGrid.EnableGridLines( True )
self.m_invoiceGrid.EnableDragGridSize( False )
self.m_invoiceGrid.SetMargins( 0, 0 )
# Populate Table
col=0
for x in p:
row=0
# if amount of invoice is smaller than the amount recieved yet, colour the cell red
if float(x['amount']) > float(x['amountRecieved']):
self.m_invoiceGrid.SetCellTextColour(row, 4, wx.Colour(255, 128, 128))
for y in list(x.values()):
self.m_invoiceGrid.SetCellValue(col, row, str(y))
row = row+1
col = col+1
# Columns
self.m_invoiceGrid.SetColSize( 0, 30 )
self.m_invoiceGrid.SetColSize( 1, 100 )
self.m_invoiceGrid.SetColSize( 2, 120 )
self.m_invoiceGrid.SetColSize( 3, 140 )
self.m_invoiceGrid.SetColSize( 4, 160 )
self.m_invoiceGrid.SetColSize( 5, 210 )
self.m_invoiceGrid.SetColSize( 6, 230 )
self.m_invoiceGrid.SetColSize( 7, 250 )
self.m_invoiceGrid.SetColSize( 8, 270 )
self.m_invoiceGrid.SetColSize( 9, 300 )
#self.m_invoiceGrid.AutoSizeColumns()
self.m_invoiceGrid.EnableDragColMove( True )
self.m_invoiceGrid.EnableDragColSize( True )
self.m_invoiceGrid.SetColLabelSize( 30 )
self.m_invoiceGrid.SetColLabelValue( 0, u"ID" )
self.m_invoiceGrid.SetColLabelValue( 1, u"Date" )
self.m_invoiceGrid.SetColLabelValue( 2, u"Time" )
self.m_invoiceGrid.SetColLabelValue( 3, u"Amount" )
self.m_invoiceGrid.SetColLabelValue( 4, u"Amount Recieved" )
self.m_invoiceGrid.SetColLabelValue( 5, u"Bilty" )
self.m_invoiceGrid.SetColLabelValue( 6, u"Agency" )
self.m_invoiceGrid.SetColLabelValue( 7, u"Customer ID" )
self.m_invoiceGrid.SetColLabelValue( 8, u"Customer Name" )
self.m_invoiceGrid.SetColLabelValue( 9, u"Customer Contact" )
self.m_invoiceGrid.SetColLabelAlignment( wx.ALIGN_CENTRE, wx.ALIGN_CENTRE )
# Rows
self.m_invoiceGrid.EnableDragRowSize( False )
self.m_invoiceGrid.SetRowLabelSize( 1 )
self.m_invoiceGrid.SetRowLabelAlignment( wx.ALIGN_CENTRE, wx.ALIGN_CENTRE )
# Label Appearance
# Cell Defaults
self.m_invoiceGrid.SetDefaultCellAlignment( wx.ALIGN_CENTRE, wx.ALIGN_TOP )
bSizer11.Add( self.m_invoiceGrid, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
self.SetSizer( bSizer11 )
self.Layout()
bSizer11.Fit( self )
self.m_invoiceGrid.Bind( wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.updateCollectedMoney )
def populateTable (self):
qry = 'select i.id, SUBSTRING(i.timeStamp, 1, 11), SUBSTRING(i.timeStamp, 12), i.amount, i.amountRecieved, i.transportKey, i.transportAgency, c.id, c.name, c.contact from customer c, invoice i where i.buyerId = c.id ORDER BY i.id'
con = connectToDB()
curs = con.cursor()
curs.execute(qry)
inv = []
while (1):
r = curs.fetchone()
if (r is not None):
inv.append(r)
else:
return inv
def updateInvoices (self):
self.m_invoiceGrid.DeleteRows(numRows=self.m_invoiceGrid.GetNumberRows())
p = self.populateTable()
lenP = len(p)
self.m_invoiceGrid.InsertRows(numRows=lenP)
# Populate Table
col=0
for x in p:
row=0
x = list(x.values())
if float(x[3]) > float(x[4]):
self.m_invoiceGrid.SetCellBackgroundColour(x[0], 4, wx.Colour(255, 128, 128))
for y in x:
self.m_invoiceGrid.SetCellValue(col, row, str(y))
row = row+1
col = col+1
def updateCollectedMoney (self, event):
iid = self.m_invoiceGrid.GetCellValue(event.GetRow(), 0)
cid = self.m_invoiceGrid.GetCellValue(event.GetRow(), 6)
dlg = uim.GetData(self, iid, cid)
dlg.ShowModal()
self.updateInvoices()