-
Notifications
You must be signed in to change notification settings - Fork 0
/
frmViewReceipts.frm
390 lines (373 loc) · 13.2 KB
/
frmViewReceipts.frm
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
VERSION 5.00
Object = "{CFC13920-9EF4-11D0-B72F-0000C04D4C0A}#6.0#0"; "mswless.ocx"
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX"
Begin VB.Form frmViewReceipts
BorderStyle = 1 'Fixed Single
Caption = "View Receipts Details"
ClientHeight = 7785
ClientLeft = 45
ClientTop = 390
ClientWidth = 17430
HelpContextID = 30
Icon = "frmViewReceipts.frx":0000
LinkTopic = "Form3"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 7785
ScaleWidth = 17430
StartUpPosition = 2 'CenterScreen
Begin MSFlexGridLib.MSFlexGrid gridResults
Height = 5415
Left = 240
TabIndex = 1
Top = 960
Width = 16815
_ExtentX = 29660
_ExtentY = 9551
_Version = 393216
FixedRows = 0
FixedCols = 0
AllowBigSelection= 0 'False
SelectionMode = 1
AllowUserResizing= 1
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "Consolas"
Size = 9.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
End
Begin MSWLess.WLCommand btnShowAll
Height = 975
Left = 2760
TabIndex = 5
Top = 6600
Width = 2535
_ExtentX = 4471
_ExtentY = 1720
_Version = 393216
Caption = "&Show Approved"
ForeColor = -1
BackColor = -2147483633
Appearance = 1
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "Consolas"
Size = 14.25
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
End
Begin MSWLess.WLCommand btnExit
Height = 975
Left = 12480
TabIndex = 4
Top = 6600
Width = 2535
_ExtentX = 4471
_ExtentY = 1720
_Version = 393216
Caption = "E&xit"
ForeColor = -1
BackColor = -2147483633
Appearance = 1
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "Consolas"
Size = 14.25
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
End
Begin MSWLess.WLCommand btnEdit
Height = 975
Left = 6000
TabIndex = 3
Top = 6600
Width = 2535
_ExtentX = 4471
_ExtentY = 1720
_Version = 393216
Caption = "&Edit"
ForeColor = -1
BackColor = -2147483633
Appearance = 1
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "Consolas"
Size = 14.25
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
End
Begin MSWLess.WLCommand btnChangeStatus
Height = 975
Left = 9240
TabIndex = 2
Top = 6600
Width = 2535
_ExtentX = 4471
_ExtentY = 1720
_Version = 393216
Caption = "&Change Status"
ForeColor = -1
BackColor = -2147483633
Appearance = 1
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "Consolas"
Size = 14.25
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
End
Begin VB.Label lblTitle
Alignment = 2 'Center
Caption = "Receipt"
BeginProperty Font
Name = "Javanese Text"
Size = 24
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 735
Left = 240
TabIndex = 0
Top = 0
Width = 16935
End
End
Attribute VB_Name = "frmViewReceipts"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim SelectedRow As Integer
Dim query As String
Private Sub btnChangeStatus_Click()
Dim currentStatus As String
SelectedReceipt = gridResults.TextMatrix(gridResults.Row, 0)
ExecuteSQL2 "Select * from Receipt where Receipt_ID = '" & SelectedReceipt & "'"
currentStatus = rs2!Status
If currentStatus = "Approved" Then
rs2.Fields!Status = "Rejected"
UpdateQuantity rs2.Fields!Model_ID, False, rs2.Fields!Quantity
Else
rs2!Status = "Approved"
UpdateQuantity rs2.Fields!Model_ID, True, rs2.Fields!Quantity
End If
rs2.Update
MsgBox "Status changed", vbInformation, "Information"
FillGrid
End Sub
Sub UpdateQuantity(ModelID As Integer, IsRemovingVehicles As Boolean, CarsSold As Integer)
Dim currentQuantity As Double
ExecuteSQL "Select * from Vehicle where ID = " & ModelID
currentQuantity = CDbl(rs.Fields!Quantity)
If IsRemovingVehicles Then
currentQuantity = currentQuantity - CarsSold
Else
currentQuantity = currentQuantity + CarsSold
End If
rs.Fields!Quantity = currentQuantity
rs.Update
End Sub
Private Sub btnExit_Click()
Unload Me
End Sub
Private Sub btnShowAll_Click()
If btnShowAll.Caption = "&Show Approved" Then
query = "Select * from Receipt where Status = 'Approved' Order by Receipt_ID Asc"
FillGrid
btnShowAll.Caption = "&Show Rejected"
ElseIf btnShowAll.Caption = "&Show Rejected" Then
query = "Select * from Receipt where Status = 'Rejected' Order by Receipt_ID Asc"
FillGrid
btnShowAll.Caption = "&Show All"
ElseIf btnShowAll.Caption = "&Show All" Then
query = "Select * from Receipt Order by Receipt_ID Asc"
FillGrid
btnShowAll.Caption = "&Show Approved"
End If
End Sub
Private Sub Form_Load()
query = "Select * from Receipt Order by Receipt_ID Asc"
FillGrid
End Sub
Sub FillGrid()
Dim ManufacturerName As String, ModelName As String, SellerName As String
Dim value As String
Dim BooleanValue As Variant
gridResults.Clear
ExecuteSQL query
With gridResults
.Cols = 12
.FixedCols = 0
.Rows = 0
.AddItem "Receipt ID" & vbTab & "Name" & vbTab & "Last Name" _
& vbTab & "Manufacturer" & vbTab & "Model" & vbTab & "Quantity" _
& vbTab & "Seller" & vbTab & "Vehicle Insurance" & vbTab & "Third Person Insurance" _
& vbTab & "SubTotal" & vbTab & "Total" & vbTab & "Status"
AutoFitRows
Dim i As Integer, j As Integer, k As Integer
i = 1
k = 0
If rs.RecordCount = 0 Then
.Rows = 2
.FixedRows = 1
.Row = 0
Exit Sub
End If
While Not rs.EOF
.Rows = .Rows + 1
For j = 1 To .Cols
If j = 4 Then
ManufacturerName = GetManufacturerName(rs.Fields(j))
value = ManufacturerName
ElseIf j = 5 Then
ModelName = GetModelName(rs.Fields(j))
value = ModelName
.ColAlignment(k) = flexAlignLeftCenter
ElseIf j = 6 Then
value = rs.Fields(j)
value = Format(value, "#,###")
ElseIf j = 7 Then
SellerName = GetSellerName(rs.Fields(j))
value = SellerName
ElseIf j = 8 Or j = 9 Then
BooleanValue = rs.Fields(j)
If BooleanValue = True Then
value = "Yes"
Else
value = "No"
End If
ElseIf j = 10 Or j = 11 Then
value = rs.Fields(j)
value = Format(value, "$#,###")
Else
value = rs.Fields(j)
End If
.TextMatrix(i, k) = value
k = k + 1
Next
rs.MoveNext
i = i + 1
k = 0
Wend
.FixedRows = 1
.AllowUserResizing = flexResizeColumns
End With
End Sub
Sub AutoFitRows()
Dim i As Integer
Dim Twips As Integer
With gridResults
For i = 0 To .Cols - 1
Twips = Me.TextWidth(.TextMatrix(0, i))
.ColWidth(i) = Twips * Me.gridResults.Font.Size / Me.Font.Size + 530 '* Screen.TwipsPerPixelX
Next i
End With
End Sub
Function GetSellerName(SellerID As Integer) As String
ExecuteSQL3 "Select * from Staff where ID = " & SellerID
GetSellerName = rs3.Fields!Staff_Name & " " & rs3.Fields!Staff_LastName
End Function
Function GetModelName(ModelID As Integer) As String
ExecuteSQL3 "Select * from Vehicle where ID = " & ModelID
GetModelName = rs3.Fields!Vehicle_Name
End Function
Function GetManufacturerName(ManufacturerID As Integer) As String
ExecuteSQL3 "Select * from Brand where ID = " & ManufacturerID
GetManufacturerName = rs3.Fields!Brand_Name
End Function
Private Sub gridResults_DblClick()
Dim SelectedReceipt As String
SelectedReceipt = gridResults.TextMatrix(gridResults.Row, 0)
ExecuteSQL2 "Select * from Receipt where Receipt_ID = '" & SelectedReceipt & "'"
If rs2.EOF Or rs2.RecordCount = 0 Then
MsgBox "Please select a valid item", vbCritical, "Error"
Exit Sub
End If
Dim ManufacturerName As String, ModelName As String, SellerName As String, SellerDNI As String
Dim ManufacturerIndex As Integer, ModelIndex As Integer, SellerIndex As Integer
Dim f As frmCreateNewReceipt
Set f = New frmCreateNewReceipt
f.txtID = rs2.Fields!Receipt_ID
f.txtName = rs2.Fields!Client_Name
f.txtLastName = rs2.Fields!Client_LastName
ManufacturerName = GetManufacturerName(rs2.Fields!Manufacturer_ID)
ManufacturerIndex = GetManufacturerIndex(ManufacturerName, f)
f.cmbManufacturer.Text = f.cmbManufacturer.List(ManufacturerIndex)
ModelName = GetModelName(rs2.Fields!Model_ID)
ModelIndex = GetModelIndex(ModelName, f)
f.cmbModel.Text = f.cmbModel.List(ModelIndex)
f.txtQuantity = rs2.Fields!Quantity
SellerDNI = GetSellerDNI(rs2.Fields!Seller_ID)
SellerIndex = GetSellerIndex(SellerDNI, f)
f.cmbSeller.Text = f.cmbSeller.List(SellerIndex)
f.chk3PersonInsurance = rs2.Fields!Third_Person_Insurance
f.chkVehicleInsurance = rs2.Fields!Vehicle_Insurance
f.txtSubTotal = rs2.Fields!Subtotal
f.txtTotal = rs2.Fields!Total
f.btnCreate.Caption = "&Update"
f.btnReset.Enabled = False
f.PreviousStatus = rs2.Fields!Status
f.SubTotalValue = f.txtSubTotal
f.TotalValue = f.txtTotal
f.FormatSubTotalValue
f.Show vbModal, Me
SelectedRow = gridResults.Row
FillGrid
gridResults.Row = SelectedRow
End Sub
Function GetSellerDNI(SellerID As Integer) As String
ExecuteSQL3 "Select * from Staff where ID = " & SellerID
GetSellerDNI = rs3.Fields!DNI
End Function
Function GetSellerIndex(SellerDNI As String, CreateReceiptForm As frmCreateNewReceipt) As Integer
Dim i As Integer, value As Integer
For i = 0 To CreateReceiptForm.cmbSeller.ListCount - 1
If InStr(1, CreateReceiptForm.cmbModel.List(i), SellerDNI, vbTextCompare) > 0 Then
value = i
Exit For
End If
Next i
GetSellerIndex = value
End Function
Function GetModelIndex(ModelName As String, CreateReceiptForm As frmCreateNewReceipt) As Integer
Dim i As Integer, value As Integer
For i = 0 To CreateReceiptForm.cmbModel.ListCount - 1
If CreateReceiptForm.cmbModel.List(i) = ModelName Then
value = i
Exit For
End If
Next i
GetModelIndex = value
End Function
Function GetManufacturerIndex(ManufacturerName As String, CreateReceiptForm As frmCreateNewReceipt) As Integer
Dim i As Integer, value As Integer
For i = 0 To CreateReceiptForm.cmbManufacturer.ListCount - 1
If CreateReceiptForm.cmbManufacturer.List(i) = ManufacturerName Then
value = i
Exit For
End If
Next i
GetManufacturerIndex = value
End Function
Private Sub btnEdit_Click()
gridResults_DblClick
End Sub