This commit is contained in:
Aritra Banik 2024-03-24 16:14:37 +05:30
parent e8760ab1a7
commit 53dfa0f257
9 changed files with 51 additions and 12 deletions

Binary file not shown.

BIN
src/a3

Binary file not shown.

View File

@ -533,6 +533,19 @@
<td> $ 77.99 </td> <td> $ 77.99 </td>
<td> May 15, 2015 </td> <td> May 15, 2015 </td>
</tr> </tr>
{% for (id, user) in users.pairs() %}
<tr>
<td class="py-1">
<img src="/a3b/admin/images/faces-clipart/pic-1.png" alt="image" />
</td>
<td> {{user.lastName}} </td>
<td> {{user.email}} </td>
<td> {{user.totalQuantity}} </td>
<td> {{user.totalPrice}} </td>
</tr>
{% endfor %}
<tr> <tr>
<td class="py-1"> <td class="py-1">
<img src="/a3b/admin/images/faces-clipart/pic-2.png" alt="image" /> <img src="/a3b/admin/images/faces-clipart/pic-2.png" alt="image" />

View File

@ -330,6 +330,7 @@
<tbody> <tbody>
{% var total: float = 0.0 %} {% var total: float = 0.0 %}
{% for (id, product) in products.pairs() %} {% for (id, product) in products.pairs() %}
<div><input type="hidden" name="product" value="{{product.id}}"></div>
<tr> <tr>
<td>{{product.name}} <strong class="mx-2">x</strong> {{toFloat(cart[id].quantity)}}</td> <td>{{product.name}} <strong class="mx-2">x</strong> {{toFloat(cart[id].quantity)}}</td>
<td>₹{{toFloat(cart[id].quantity)*product.price}}</td> <td>₹{{toFloat(cart[id].quantity)*product.price}}</td>

View File

@ -87,4 +87,7 @@ proc drop*(db: DbConn) =
proc getPriceByProductName*(db: DbConn, name: string): float = proc getPriceByProductName*(db: DbConn, name: string): float =
## getPriceByProductName returns the price of a product by its name ## getPriceByProductName returns the price of a product by its name
var row = db.getRow(sql"SELECT price FROM products WHERE name = ?", name) var row = db.getRow(sql"SELECT price FROM products WHERE name = ?", name)
return parseFloat(row[0]) return parseFloat(row[0])
proc getProductIdByProductName*(db: DbConn, name: string): int=
result = parseInt(db.getValue(sql"SELECT id FROM products WHERE name=?", name))

View File

@ -59,10 +59,12 @@ proc getUser*(db: DbConn, email, password: string): User =
return user return user
proc getUserOrdersAmount*(db: DbConn, userId: int): (int, int)= proc getUserOrdersAmount*(db: DbConn, userId: int): (int, int)=
echo userId
var var
row = db.getAllRows(sql"SELECT product_id, quantity FROM orders WHERE user_id=?", userId) row = db.getAllRows(sql"SELECT (product_id, quantity) FROM orders WHERE user_id=?", userId)
totalQuantity = 0 totalQuantity = 0
totalPrice = 0 totalPrice = 0
echo row
for b, c in row: for b, c in row:
var var
quantity = c[1] quantity = c[1]

View File

@ -1,10 +1,14 @@
import import
mike, mike,
nimja, nimja,
./a3pkg/mics ./a3pkg/mics,
./a3c/users
proc admin*(ctx: Context): string= proc admin*(ctx: Context): string=
var var
db = newDatabase() db = newDatabase()
users = db.getUserCartTable()
echo users
compileTemplateFile(getScriptDir() / "a3a" / "admin" / "index.html") compileTemplateFile(getScriptDir() / "a3a" / "admin" / "index.html")

View File

@ -23,6 +23,8 @@ proc checkOut*(ctx: Context): string=
productName = qParams.getOrDefault("prod", "") productName = qParams.getOrDefault("prod", "")
quantity = parseInt(qParams.getOrDefault("quantity", "0")) quantity = parseInt(qParams.getOrDefault("quantity", "0"))
# p = seq[int]
if email != "": if email != "":
productCount = micsCartProductCount(email, password) productCount = micsCartProductCount(email, password)
@ -34,8 +36,9 @@ proc checkOut*(ctx: Context): string=
product: Products product: Products
ca: Cart ca: Cart
product.id = 1 product.id = db.getProductIdByProductName(productName)
product.name = productName product.name = productName
# p1 = db.getProductIdByProductName(productName)
product.price = db.getPriceByProductName(productName) product.price = db.getPriceByProductName(productName)
ca.quantity = quantity ca.quantity = quantity
products.add(product) products.add(product)
@ -51,4 +54,4 @@ proc checkOut*(ctx: Context): string=
var product = db.getProductById(d.productId) var product = db.getProductById(d.productId)
products.add(product) products.add(product)
compileTemplateFile(getScriptDir() / "a3a" / "checkout.nimja") compileTemplateFile(getScriptDir() / "a3a" / "checkout.nimja")

View File

@ -44,12 +44,13 @@ proc validationCheckOut*(ctx: Context) =
order: Orders order: Orders
user: User user: User
order.userId = userId # order.userId = userId
order.country = country # order.country = country
order.address = address # order.address = address
order.state = state # order.state = state
order.postalCode = zip # order.postalCode = zip
order.phoneNumber = phone # order.phoneNumber = phone
# order.productId = 0
user.firstName = firstName user.firstName = firstName
user.lastName = lastName user.lastName = lastName
@ -61,10 +62,22 @@ proc validationCheckOut*(ctx: Context) =
db.createPost(user) db.createPost(user)
db.clearCart(userId) db.clearCart(userId)
var _ = db.createOrder(order) # var _ = db.createOrder(order)
for c, d in cart: for c, d in cart:
var product = db.getProductById(d.productId) var product = db.getProductById(d.productId)
order.userId = userId
order.country = country
order.address = address
order.state = state
order.postalCode = zip
order.phoneNumber = phone
order.productId = d.productId
order.quantity = d.quantity
var _ = db.createOrder(order)
products.add(product) products.add(product)
ctx.send(sendThankYou()) ctx.send(sendThankYou())