-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFilemodule.bas
More file actions
468 lines (370 loc) · 14.8 KB
/
Filemodule.bas
File metadata and controls
468 lines (370 loc) · 14.8 KB
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
Attribute VB_Name = "FileModule"
'***********************************************************************************************
'** Prometheus - Libreria Lerma Stock
'** es una aplicacion desarrollada exclusivamente para llevar a cabo las tareas relacionadas
'** con el control de stock de la libreria. Control de Vueltos y otras tareas necesarias
'** que dependen de mi exclusiva responsabilidad.
'** -------------------------------------------------------------------------------------------
'** Desarrollado por: Christian Adrian Del Monte
'** Dudas o consultas: creadig@gmail.com / creadig@hotmail.com
'** Ultima actualizacion: Agosto 2019
'***********************************************************************************************
Public Type STKDatabase
Aid As Long
CodeSec As String * 20
ArtName As String * 50
Exis As String * 6
Precio As String * 10
End Type
Public Type VentasData 'tipo para controlar los articulos de vuelto en ventas
Vid As Integer 'identificador de registro o numero de id (unico)
Vdate As String * 10 'fecha de carga de datos o fecha de venta o baja del aticulo
VSuc As Long 'numero de sucursal involucrada en la transaccion
VTurno As Integer 'turno responsable (1=mañana - 2=tarde)
VICode As String * 8 'codigo del articulo
VIDesc As String * 100 'descripcion del articulo
VICosto As String * 10 'precio del articulo
VICant As Integer 'Cantidad de articulos
VRendido As Integer 'articulo rendido? dado de baja? 1=si 0=no
VRdate As String * 10 'fecha de rendicion
VROp As String * 20 'numero de comprobante de operacion
End Type
Public cnn As ADODB.Connection
Public ControlVentas As VentasData 'para el control de vueltos de ventas
Public StockDatabase As STKDatabase 'base de datos general de la aplicacion
Public Const InvFilename = "\Database\L_L_Stock.llk"
Public Const VentasExt = ".inv"
Public Const RendVentasExt = ".ipk"
'// ***************************************************************************************************
'/// Funcion para consultar de la base de inventario de articulos
'/// REVISAR REVISAR REVISAR REVISAR REVISAR REVISAR REVISAR
Public Function CargaInventario(Wid As Long) As STKDatabase
Dim LastReg As Long, i As Long
'/// abrimos el archivo de productos
'On Error GoTo err
Open App.Path & InvFilename For Random As #16 Len = Len(StockDatabase)
'/// check for the ID to load
If Wid <> 0 Then
LastReg = Wid
Else
GoTo err
End If
'/// cargamos
Get #16, LastReg, StockDatabase
CargaInventario.Aid = StockDatabase.Aid
CargaInventario.ArtName = Trim(StockDatabase.ArtName)
CargaInventario.CodeSec = Trim(StockDatabase.CodeSec)
CargaInventario.Exis = Trim(StockDatabase.Exis)
CargaInventario.Precio = Trim(StockDatabase.Precio)
Close #16
Exit Function
'/// if there is an error ------------------------------------------
err:
'WriteErrors "Error en SaveINVData > Module INV. - " & err.Number & " - " & err.Description
Close #16
StockDatabase.Aid = -1
CargaInventario.Aid = StockDatabase.Aid
End Function
'// ***************************************************************************************************
'/// Funcion para actualizar y crear la base de inventario de articulos
'/// todos los articulos de la libreria en stock deben ir aqui.
Public Function GuardaInventario(Dato As STKDatabase, WOptionalID As Long) As Boolean
Dim LastReg As Long
'/// abrimos el archivo de productos
On Error GoTo err
Open App.Path & InvFilename For Random As #12 Len = Len(Dato)
'/// check for the ID to save
If WOptionalID = 0 Or WOptionalID = -1 Then
LastReg = LOF(12) \ Len(STKDatabase)
LastReg = LastReg + 1
Else
LastReg = WOptionalID
End If
'/// seteamos los datos del inventario a guardar
StockDatabase.Aid = LastReg
StockDatabase.ArtName = Trim(Dato.ArtName)
StockDatabase.CodeSec = Trim(Dato.CodeSec)
StockDatabase.Exis = Trim(Dato.Exis)
StockDatabase.Precio = Trim(Dato.Precio)
'/// guardamos
Put #12, LastReg, StockDatabase
Close #12
GuardaInventario = True
Exit Function
'/// if there is an error ------------------------------------------
err:
'WriteErrors "Error en SaveINVData > Module INV. - " & err.Number & " - " & err.Description
Close #12
GuardaInventario = False
End Function
'// ***************************************************************************************************
Public Function GuardarVentas(Articulo As VentasData, WOptionalID As Integer) As Boolean
Dim FileName As String
Dim LastReg As Integer
FileName = "\Data\vlts\data" & "-" & Articulo.VSuc & VentasExt
'/// abrimos el archivo de productos
On Error GoTo err
Open App.Path & FileName For Random As #12 Len = Len(ControlVentas)
'/// check for the ID to save
If WOptionalID = 0 Or WOptionalID = -1 Then
LastReg = LOF(12) \ Len(ControlVentas)
LastReg = LastReg + 1
Else
LastReg = WOptionalID
End If
'/// seteamos los datos del inventario a guardar
ControlVentas.Vid = LastReg
ControlVentas.Vdate = Articulo.Vdate
ControlVentas.VSuc = Articulo.VSuc
ControlVentas.VTurno = Articulo.VTurno
ControlVentas.VICode = Trim(Articulo.VICode)
ControlVentas.VIDesc = Trim(Articulo.VIDesc)
ControlVentas.VICosto = Trim(Articulo.VICosto)
ControlVentas.VICant = Articulo.VICant
ControlVentas.VRendido = 0
ControlVentas.VRdate = "000000"
ControlVentas.VROp = "000000"
'/// guardamos
Put #12, LastReg, ControlVentas
Close #12
GuardarVentas = True
Exit Function
'/// if there is an error ------------------------------------------
err:
'WriteErrors "Error en SaveINVData > Module INV. - " & err.Number & " - " & err.Description
Close #12
GuardarVentas = False
End Function
'// ***************************************************************************************************
'/// funcion para buscar un articulo dentro de la base de ventas
Public Function BuscarVentas(RegId As Long, SucId As Long, Optional Rendido As Long) As VentasData
Dim LastReg As Long
Dim FileName As String
Dim BC As String
If Rendido = 1 Then
FileName = "\Data\vlts\rends\data" & "-" & SucId & RendVentasExt
LastReg = GetRendLastReg(SucId)
Else
FileName = "\Data\vlts\data" & "-" & SucId & VentasExt
LastReg = GetVentasLastReg(SucId)
End If
'/// abrimos el archivo de los abonados
On Error GoTo err
Open App.Path & FileName For Random As #14 Len = Len(ControlVentas)
If RegId < LastReg Then
Get #14, RegId, ControlVentas
BuscarVentas.Vdate = Trim(ControlVentas.Vdate)
BuscarVentas.VICant = ControlVentas.VICant
BuscarVentas.VICode = Trim(ControlVentas.VICode)
BuscarVentas.VICosto = Trim(ControlVentas.VICosto)
BuscarVentas.Vid = ControlVentas.Vid
BuscarVentas.VIDesc = Trim(ControlVentas.VIDesc)
BuscarVentas.VSuc = ControlVentas.VSuc
BuscarVentas.VTurno = ControlVentas.VTurno
BuscarVentas.VRdate = Trim(ControlVentas.VRdate)
BuscarVentas.VRendido = ControlVentas.VRendido
BuscarVentas.VROp = Trim(ControlVentas.VROp)
Else
BuscarVentas.Vid = -1
BuscarVentas.VIDesc = "Error"
End If
Close #14
Exit Function
'/// if there is an error ------------------------------------------
err:
'WriteErrors "Error en GetAGEData > Module ABN. - " & err.Number & " - " & err.Description
BuscarVentas.Vid = -1
BuscarVentas.VIDesc = "Error"
Close #14
End Function
'// ***************************************************************************************************
Public Function RendirVentas(Articulo As VentasData, WOptionalID As Integer) As Boolean
Dim FileName As String
Dim LastReg As Integer
FileName = "\Data\vlts\rends\data" & "-" & Articulo.VSuc & RendVentasExt
'/// abrimos el archivo de productos
On Error GoTo err
Open App.Path & FileName For Random As #17 Len = Len(ControlVentas)
'/// check for the ID to save
If WOptionalID = 0 Or WOptionalID = -1 Then
LastReg = LOF(17) \ Len(ControlVentas)
LastReg = LastReg + 1
Else
LastReg = WOptionalID
End If
'/// seteamos los datos del inventario a guardar
ControlVentas.Vid = LastReg
ControlVentas.Vdate = Trim(Articulo.Vdate)
ControlVentas.VSuc = Articulo.VSuc
ControlVentas.VTurno = Articulo.VTurno
ControlVentas.VICode = Trim(Articulo.VICode)
ControlVentas.VIDesc = Trim(Articulo.VIDesc)
ControlVentas.VICosto = Trim(Articulo.VICosto)
ControlVentas.VICant = Articulo.VICant
ControlVentas.VRendido = Articulo.VRendido
ControlVentas.VRdate = Trim(Articulo.VRdate)
ControlVentas.VROp = Trim(Articulo.VROp)
'/// guardamos
Put #17, LastReg, ControlVentas
Close #17
RendirVentas = True
Exit Function
'/// if there is an error ------------------------------------------
err:
'WriteErrors "Error en SaveINVData > Module INV. - " & err.Number & " - " & err.Description
Close #17
RendirVentas = False
End Function
'// ***************************************************************************************************
'/// funcion para buscar un articulo dentro de la base de datos
Public Function BuscarArticulo2(CodigoArt As Long) As STKDatabase
Dim LastReg As Long
Dim BC As String
'/// abrimos el archivo de los abonados
On Error GoTo err
Open App.Path & InvFilename For Random As #14 Len = Len(StockDatabase)
LastReg = GetInvLastReg
If CodigoArt < LastReg Then
Get #14, CodigoArt, StockDatabase
BuscarArticulo2.ArtName = Trim(StockDatabase.ArtName)
BuscarArticulo2.Precio = Trim(StockDatabase.Precio)
BuscarArticulo2.Aid = StockDatabase.Aid
BuscarArticulo2.CodeSec = Trim(StockDatabase.CodeSec)
BuscarArticulo2.Exis = Trim(StockDatabase.Exis)
Else
BuscarArticulo2.Aid = -1
BuscarArticulo2.ArtName = "Error"
End If
Close #14
Exit Function
'/// if there is an error ------------------------------------------
err:
'WriteErrors "Error en GetAGEData > Module ABN. - " & err.Number & " - " & err.Description
BuscarArticulo2.ArtName = "Error"
Close #14
End Function
'// ***************************************************************************************************
'// funcion para extraer de un archivo los datos de creacion y ultima modificacion
Public Function GetFechaArch(Path As String) As String
'Variable de tipo FileSystemObject y File
Dim o_Fso As New FileSystemObject
Dim Archivo As File
' Lee las propiedades del archivo mediante GetFile
On Error GoTo err
Set Archivo = o_Fso.GetFile(Path)
'Visualiza el resultado: Creación ,acceso y modificado etc..
'MsgBox "Fecha de creación del archivo: " & Format(Archivo.DateCreated), vbInformation
'MsgBox "Fecha de modificación : " & Format(Archivo.DateLastModified), vbInformation
GetFechaArch = Format(Archivo.DateLastModified)
'MsgBox "Fecha de del último acceso: " & Format(Archivo.DateLastAccessed), vbInformation
'MsgBox "Tamaño del archivo : " & Format(Archivo.Size) & " Bytes", vbInformation
'MsgBox "Tipo de archivo : " & Format(Archivo.Type), vbInformation
' Elimina las variables de objeto
Set Archivo = Nothing
Set o_Fso = Nothing
Exit Function
'/// if there is an error ------------------------------------------
err:
Set Archivo = Nothing
Set o_Fso = Nothing
GetFechaArch = "Inexistente"
End Function
'// ***************************************************************************************************
'/// Funcion para extraer el ultimo registro de la base de inventario de articulos
Public Function GetInvLastReg() As Long
Dim LastReg As Long
'/// abrimos el archivo de productos
'On Error GoTo err
Open App.Path & InvFilename For Random As #12 Len = Len(StockDatabase)
'/// check for the last ID
LastReg = LOF(12) \ Len(StockDatabase)
LastReg = LastReg + 1
Close #12
GetInvLastReg = LastReg
Exit Function
'/// if there is an error ------------------------------------------
err:
'WriteErrors "Error en SaveINVData > Module INV. - " & err.Number & " - " & err.Description
Close #12
GetInvLastReg = -1
End Function
'// ***************************************************************************************************
'/// Funcion para extraer el ultimo registro de la base de ventas de articulos
Public Function GetVentasLastReg(NumSuc As Long) As Long
Dim LastReg As Long, FileName As String
FileName = "\Data\vlts\data" & "-" & NumSuc & VentasExt
'/// abrimos el archivo de productos
'On Error GoTo err
Open App.Path & FileName For Random As #11 Len = Len(ControlVentas)
'/// check for the last ID
LastReg = LOF(11) \ Len(ControlVentas)
LastReg = LastReg + 1
Close #11
GetVentasLastReg = LastReg
Exit Function
'/// if there is an error ------------------------------------------
err:
'WriteErrors "Error en SaveINVData > Module INV. - " & err.Number & " - " & err.Description
Close #11
GetVentasLastReg = -1
End Function
'// ***************************************************************************************************
'/// Funcion para extraer el ultimo registro de la base de ventas de articulos
Public Function GetRendLastReg(NumSuc As Long) As Long
Dim LastReg As Long, FileName As String
FileName = "\Data\vlts\rends\data" & "-" & NumSuc & RendVentasExt
'/// abrimos el archivo de productos
'On Error GoTo err
Open App.Path & FileName For Random As #11 Len = Len(ControlVentas)
'/// check for the last ID
LastReg = LOF(11) \ Len(ControlVentas)
LastReg = LastReg + 1
Close #11
GetRendLastReg = LastReg
Exit Function
'/// if there is an error ------------------------------------------
err:
'WriteErrors "Error en SaveINVData > Module INV. - " & err.Number & " - " & err.Description
Close #11
GetRendLastReg = -1
End Function
'// ***************************************************************************************************
'// funcion para buscar la descripcion de un articulo por su codigo principal o secundario (de barras)
'// retorna la descripcion del articulo buscado o "ERR" en caso de no encontrar nada
'// ***************************************************************************************************
Public Function BuscarArticuloMDB(PrimaryMDB As String, CodigoArt As String) As String
Dim s As String
Dim tRs As ADODB.Recordset
Dim n As Long
Set cnn = New ADODB.Connection
Provider = "Microsoft.Jet.OLEDB.4.0"
cnn.Open "Provider=" & Provider & "; Data Source=" & PrimaryMDB
Set tRs = New ADODB.Recordset
DoEvents
CodigoArt = Trim(CodigoArt)
If Len(CodigoArt) = 5 Then
CodigoArt = "0" & CodigoArt
End If
s = "SELECT * FROM VALORSTK WHERE codart LIKE ""%" & CodigoArt & "%"";"
tRs.Open s, cnn, adOpenDynamic, adLockOptimistic 'adLockOptimistic
With tRs
If (.EOF = True) And (.BOF = True) Then
' Si no hay datos...
'MsgBox "No se encontro el Articulo"
BuscarArticuloMDB = "NO ENCONTRADO"
tRs.Close
cnn.Close
Exit Function
Else
n = 0
Do While Not .EOF
n = n + 1
BuscarArticuloMDB = Trim(tRs.Fields("nombre"))
.MoveNext
Loop
End If
End With
tRs.Close
'tRs.Close
cnn.Close
End Function