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> May 15, 2015 </td>
</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>
<td class="py-1">
<img src="/a3b/admin/images/faces-clipart/pic-2.png" alt="image" />

View File

@ -330,6 +330,7 @@
<tbody>
{% var total: float = 0.0 %}
{% for (id, product) in products.pairs() %}
<div><input type="hidden" name="product" value="{{product.id}}"></div>
<tr>
<td>{{product.name}} <strong class="mx-2">x</strong> {{toFloat(cart[id].quantity)}}</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 =
## getPriceByProductName returns the price of a product by its 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
proc getUserOrdersAmount*(db: DbConn, userId: int): (int, int)=
echo userId
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
totalPrice = 0
echo row
for b, c in row:
var
quantity = c[1]

View File

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

View File

@ -23,6 +23,8 @@ proc checkOut*(ctx: Context): string=
productName = qParams.getOrDefault("prod", "")
quantity = parseInt(qParams.getOrDefault("quantity", "0"))
# p = seq[int]
if email != "":
productCount = micsCartProductCount(email, password)
@ -34,8 +36,9 @@ proc checkOut*(ctx: Context): string=
product: Products
ca: Cart
product.id = 1
product.id = db.getProductIdByProductName(productName)
product.name = productName
# p1 = db.getProductIdByProductName(productName)
product.price = db.getPriceByProductName(productName)
ca.quantity = quantity
products.add(product)
@ -51,4 +54,4 @@ proc checkOut*(ctx: Context): string=
var product = db.getProductById(d.productId)
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
user: User
order.userId = userId
order.country = country
order.address = address
order.state = state
order.postalCode = zip
order.phoneNumber = phone
# order.userId = userId
# order.country = country
# order.address = address
# order.state = state
# order.postalCode = zip
# order.phoneNumber = phone
# order.productId = 0
user.firstName = firstName
user.lastName = lastName
@ -61,10 +62,22 @@ proc validationCheckOut*(ctx: Context) =
db.createPost(user)
db.clearCart(userId)
var _ = db.createOrder(order)
# var _ = db.createOrder(order)
for c, d in cart:
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)
ctx.send(sendThankYou())