-
Notifications
You must be signed in to change notification settings - Fork 60
/
supplierInfoPanel.py
114 lines (90 loc) · 3.41 KB
/
supplierInfoPanel.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
# 26th May, 2018 5:05pm
import wx
import wx.grid
import wx.xrc
import wx.dataview
from connectToDb import connectToDB
class supplierInfoPanel ( 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_custInfoGrid = wx.grid.Grid( self, wx.ID_ANY, wx.DefaultPosition, wx.Size( -1,700 ), 0 )
p = self.populateTable()
lenP = len(p)
# Grid
self.m_custInfoGrid.CreateGrid( lenP, 5 )
self.m_custInfoGrid.EnableEditing( False )
self.m_custInfoGrid.EnableGridLines( True )
self.m_custInfoGrid.EnableDragGridSize( False )
self.m_custInfoGrid.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['balance']) > 0:
self.m_custInfoGrid.SetCellTextColour(row, 4, wx.Colour(255, 128, 128))
for y in list(x.values()):
self.m_custInfoGrid.SetCellValue(col, row, str(y))
row = row+1
col = col+1
# Columns
self.m_custInfoGrid.SetColSize( 0, 30 )
self.m_custInfoGrid.SetColSize( 1, 100 )
self.m_custInfoGrid.SetColSize( 2, 120 )
self.m_custInfoGrid.SetColSize( 3, 140 )
#self.m_custInfoGrid.AutoSizeColumns()
self.m_custInfoGrid.EnableDragColMove( True )
self.m_custInfoGrid.EnableDragColSize( True )
self.m_custInfoGrid.SetColLabelSize( 30 )
self.m_custInfoGrid.SetColLabelValue( 0, u"ID" )
self.m_custInfoGrid.SetColLabelValue( 1, u"Name" )
self.m_custInfoGrid.SetColLabelValue( 2, u"Contact" )
self.m_custInfoGrid.SetColLabelValue( 3, u"Address" )
self.m_custInfoGrid.SetColLabelValue( 4, u"Balance" )
self.m_custInfoGrid.SetColLabelAlignment( wx.ALIGN_CENTRE, wx.ALIGN_CENTRE )
# Rows
self.m_custInfoGrid.EnableDragRowSize( False )
self.m_custInfoGrid.SetRowLabelSize( 1 )
self.m_custInfoGrid.SetRowLabelAlignment( wx.ALIGN_CENTRE, wx.ALIGN_CENTRE )
# Label Appearance
# Cell Defaults
self.m_custInfoGrid.SetDefaultCellAlignment( wx.ALIGN_CENTRE, wx.ALIGN_TOP )
bSizer11.Add( self.m_custInfoGrid, 0, wx.ALIGN_CENTRE|wx.ALL, 5 )
self.SetSizer( bSizer11 )
self.Layout()
bSizer11.Fit( self )
#self.m_custInfoGrid.Bind( wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.updateCollectedMoney )
def populateTable (self):
qry = 'select s.id, s.name, s.iban, s.contact, sum(p.totalBill - p.amountPaid) as balance from purchase p, supplier s where p.supplier = s.id group by s.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 updateSuppliers (self):
self.m_custInfoGrid.DeleteRows(numRows=self.m_custInfoGrid.GetNumberRows())
p = self.populateTable()
lenP = len(p)
self.m_custInfoGrid.InsertRows(numRows=lenP)
# Populate Table
col=0
for x in p:
row=0
x = list(x.values())
if float(x[4]) > 0:
self.m_custInfoGrid.SetCellBackgroundColour(x[0], 4, wx.Colour(255, 128, 128))
for y in x:
self.m_custInfoGrid.SetCellValue(col, row, str(y))
row = row+1
col = col+1
def updateCollectedMoney (self, event):
iid = self.m_custInfoGrid.GetCellValue(event.GetRow(), 0)
dlg = uim.GetData(self, iid)
dlg.ShowModal()
self.updateInvoices()