-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroutes.coffee
149 lines (133 loc) · 4.1 KB
/
routes.coffee
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
# ALL ROUTES.
module.exports = (app, moongose)->
UsersController = require('./controllers/UserController')(moongose, app)
ComprasController = require('./controllers/ComprasController')(moongose, app)
ProductosController = require('./controllers/ProductosController')(moongose, app)
VentasController = require('./controllers/VentasController')(moongose, app)
# ROUTE FOR LOG PAGE.
isAut = (req, res, next)->
if req.session.aut
# console.log '2'
next()
else
res.redirect '/'
# console.log '1'
app.get '/', (req, resp)->
req.session.destroy (err)->
console.log err if err
resp.render 'pages/login', {title:'Log'}
# ROUTES FOR PAGES/
app.get '/pages/:page', isAut, (req, resp)->
console.log req.session
# resp.header('Cache-Control', 'private, no-cache, no-store, must-revalidate')
# resp.header('Expires', '-1')
# resp.header('Pragma', 'no-cache')
page = req.params.page
resp.render "pages/#{page}", {page:page, dataUser:req.session.dataUser}
# ROUTES FOR USER.
app.post '/users/login', UsersController.doLogin
app.get '/users/getAll', UsersController.getAll
app.get '/newuser/:name/:password/:estado?/:privilegios?', UsersController.newUser
#rutas y acciones(io) (route:accion) desde el cliente.
app.io.route 'users',
create:UsersController.create
delete:UsersController.delete
edit:UsersController.edit
userIn:UsersController.userIn
userOut:UsersController.userOut
# COMPRAS.
app.get '/compras/prodReg', ComprasController.prodReg
app.get '/newcompra/:serie/:codigo/:descripcion/:costo/:cantidad/:utilidad/:garantia/:proveedor', ComprasController.newCompra
#rutas y acciones(io) (route:accion) desde el cliente.
app.io.route 'compras',
shopp:ComprasController.shopp
delete:ComprasController.delete
edit:ComprasController.edit
shopping:ComprasController.shopping
# PRODUCTOS.
app.get '/productos/getAll', ProductosController.getAll
# VENTAS.
app.io.route 'ventas',
addToCart:VentasController.addToCart
delToCart:VentasController.delToCart
cancelShopp:VentasController.cancelShopp
shopp:VentasController.shopp
#TEST ROUTES.
app.get '/pdf', (req, resp)->
resp.render 'pdf'
app.get '/reporte.pdf', (req, resp)->
lorem = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam in suscipit purus. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Vivamus nec hendrerit felis. Morbi aliquam facilisis risus eu lacinia. Sed eu leo in turpis fringilla hendrerit. Ut nec accumsan nisl.'
PDFDocument = require('pdfkit')
fs = require('fs')
doc = new PDFDocument
margins:
top: 50
bottom: 50
left: 72
right: 72
# for i in [0..1000]
doc.fontSize 10
# doc.addPage
# margins:
# top: 50
# bottom: 50
# left: 72
# right: 72
doc.pipe( fs.createWriteStream('out.pdf'))
# doc.moveDown()
# doc.moveTo(100, 100)
doc.text 'INFORME', 270, 40,
x = 30
y = 70
w = 100
h = 30
npag = 1
# HEADER.
for i in [0..4]
doc.rect(x-5, y-5, w+10, h+5).lineWidth(1).fillOpacity(0.9).fillAndStroke('black', 'black')
doc.fillColor 'white'
doc.text "REPORTES #{i}", x, y+5,
width: w
height: h
align: 'center'#
# stroke:true
x += w+10
#ADD ROWS.
doc.fontSize 9
doc.fillColor 'black'
y += h+5
for j in [1...500]
if j % 18 is 0
# console.log y
doc.text "Pagina #{npag++}", 270, 710,
y = h+5
doc.addPage()
x = 30
for i in [0..4]
doc.rect(x-5, y-5, w+10, h+5).lineWidth(0.2).stroke('black')
doc.text "Marcelo Juan Cabrera Gutiérrez", x, y,
width: w
height: h
align: 'justify'#
# stroke:true
x += w+10
y += h+5
if 500 % 18 isnt 0
doc.text "Pagina #{npag++}", 270, 710,
# draw bounding rectangle
# ptox, ptoy, anchox, anchoy
# doc.moveTo(100, 100)
# .lineTo(100, 130)
# .lineTo(130, 160)
# .fill('red', 'even-odd')
# loremIpsum = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam in...'
# doc.y = 320
# doc.fillColor('black')
# doc.text(loremIpsum, {
# paragraphGap: 10,
# # indent: 20,
# align: 'left',
# columns: 3
# })
doc.pipe( resp )
doc.end()