add fidelity card module
This commit is contained in:
@@ -4,6 +4,7 @@ from admin.products import ProductsPage
|
|||||||
from admin.banner import Banner
|
from admin.banner import Banner
|
||||||
from admin.orders import OrdersPage
|
from admin.orders import OrdersPage
|
||||||
from admin.clients import Clients
|
from admin.clients import Clients
|
||||||
|
from admin.fidelity_cards import FidelityCards
|
||||||
|
|
||||||
class Dashboard:
|
class Dashboard:
|
||||||
def __init__(self, page: ft.Page):
|
def __init__(self, page: ft.Page):
|
||||||
@@ -52,6 +53,11 @@ class Dashboard:
|
|||||||
selected_icon=ft.Icon(ft.Icons.IMAGE_ROUNDED),
|
selected_icon=ft.Icon(ft.Icons.IMAGE_ROUNDED),
|
||||||
label_content=ft.Text("Banner"),
|
label_content=ft.Text("Banner"),
|
||||||
),
|
),
|
||||||
|
ft.NavigationRailDestination(
|
||||||
|
icon=ft.Icons.CARD_GIFTCARD_OUTLINED,
|
||||||
|
selected_icon=ft.Icon(ft.Icons.CARD_GIFTCARD),
|
||||||
|
label_content=ft.Text("Card de\nfidelitate"),
|
||||||
|
),
|
||||||
ft.NavigationRailDestination(
|
ft.NavigationRailDestination(
|
||||||
icon=ft.Icons.LOGOUT_OUTLINED,
|
icon=ft.Icons.LOGOUT_OUTLINED,
|
||||||
selected_icon=ft.Icon(ft.Icons.LOGOUT_ROUNDED),
|
selected_icon=ft.Icon(ft.Icons.LOGOUT_ROUNDED),
|
||||||
@@ -87,6 +93,10 @@ class Dashboard:
|
|||||||
self.placeholder.content = self.banner.build()
|
self.placeholder.content = self.banner.build()
|
||||||
self.placeholder.update()
|
self.placeholder.update()
|
||||||
case 6:
|
case 6:
|
||||||
|
self.fidelity_cards = FidelityCards(self.page)
|
||||||
|
self.placeholder.content = self.fidelity_cards.build()
|
||||||
|
self.placeholder.update()
|
||||||
|
case 7:
|
||||||
self.page.client_storage.clear()
|
self.page.client_storage.clear()
|
||||||
self.page.session.clear()
|
self.page.session.clear()
|
||||||
self.page.go('/')
|
self.page.go('/')
|
||||||
|
|||||||
230
UI_V2/admin/fidelity_cards.py
Normal file
230
UI_V2/admin/fidelity_cards.py
Normal file
@@ -0,0 +1,230 @@
|
|||||||
|
import flet as ft
|
||||||
|
from dbActions.fidelity_cards import FidelityCards as FC
|
||||||
|
|
||||||
|
class FidelityCards:
|
||||||
|
def __init__(self, page: ft.Page):
|
||||||
|
self.page = page
|
||||||
|
self.fidelity_cards_manager = FC()
|
||||||
|
|
||||||
|
self.all_cards = self.fidelity_cards_manager.get_all_fidelity_cards()
|
||||||
|
self.list_of_cars = ft.ListView(
|
||||||
|
controls=self.create_list(self.all_cards, self.on_delete_btn_click, self.on_edit_btn_click),
|
||||||
|
expand=True,
|
||||||
|
spacing=10
|
||||||
|
)
|
||||||
|
|
||||||
|
self.search_bar = ft.TextField(label = "Cauta dupa numar de telefon", on_submit=self.on_search_btn_click, expand=True)
|
||||||
|
self.search_btn = ft.IconButton(icon=ft.Icons.SEARCH, on_click=self.on_search_btn_click)
|
||||||
|
|
||||||
|
self.card_id = ft.TextField(label="Id card")
|
||||||
|
self.card_type = ft.Dropdown(
|
||||||
|
label='Reducere (%)',
|
||||||
|
options=[
|
||||||
|
ft.dropdown.Option(key='10', text="10%"),
|
||||||
|
ft.dropdown.Option(key='20', text="20%"),
|
||||||
|
ft.dropdown.Option(key='30', text="30%"),
|
||||||
|
],
|
||||||
|
expand=True
|
||||||
|
)
|
||||||
|
self.client_name = ft.TextField(label="Nume client")
|
||||||
|
self.phone_number = ft.TextField(label="Numar telefon")
|
||||||
|
|
||||||
|
self.item_to_be_edit = None
|
||||||
|
self.add_dialog = ft.AlertDialog(
|
||||||
|
title=ft.Text(value = "Adauga card de fidelitate" if self.item_to_be_edit == None else "Actualizeaza card de fidelitate"),
|
||||||
|
content=ft.Column(
|
||||||
|
[
|
||||||
|
self.card_id,
|
||||||
|
self.card_type,
|
||||||
|
self.client_name,
|
||||||
|
self.phone_number
|
||||||
|
],
|
||||||
|
height=250,
|
||||||
|
width=400
|
||||||
|
),
|
||||||
|
actions = [
|
||||||
|
ft.Button("Salveaza", on_click=self.on_save_btn_click, icon=ft.Icons.SAVE),
|
||||||
|
ft.TextButton("Anuleaza", on_click=self.on_cancel_btn_click, icon=ft.Icons.CANCEL)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
self.delete_dialog = ft.AlertDialog(
|
||||||
|
title=ft.Text("Setergeti cardul?"),
|
||||||
|
actions = [
|
||||||
|
ft.Button("Da", on_click=self.on_condifm_delete_btn_click, icon=ft.Icons.DELETE),
|
||||||
|
ft.TextButton("Nu", on_click=self.on_cancel_delete_btn_click, icon=ft.Icons.CANCEL)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
self.item_to_be_delete = None
|
||||||
|
|
||||||
|
|
||||||
|
def on_condifm_delete_btn_click(self, e):
|
||||||
|
self.fidelity_cards_manager.remove_fidelity_card(self.item_to_be_delete)
|
||||||
|
self.page.close(self.delete_dialog)
|
||||||
|
self.update_list()
|
||||||
|
self.item_to_be_delete = None
|
||||||
|
|
||||||
|
def on_cancel_delete_btn_click(self, e):
|
||||||
|
self.page.close(self.delete_dialog)
|
||||||
|
self.item_to_be_delete = None
|
||||||
|
|
||||||
|
def on_save_btn_click(self, e):
|
||||||
|
card_id = self.card_id.value
|
||||||
|
card_type = self.card_type.value
|
||||||
|
client_name = self.client_name.value
|
||||||
|
phone_number = self.phone_number.value
|
||||||
|
|
||||||
|
if self.item_to_be_edit == None:
|
||||||
|
self.fidelity_cards_manager.add_fidelity_card(
|
||||||
|
card_id,
|
||||||
|
card_type,
|
||||||
|
client_name,
|
||||||
|
phone_number
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
self.fidelity_cards_manager.update_card(
|
||||||
|
self.item_to_be_edit,
|
||||||
|
card_id,
|
||||||
|
card_type,
|
||||||
|
client_name,
|
||||||
|
phone_number
|
||||||
|
)
|
||||||
|
self.item_to_be_edit = None
|
||||||
|
|
||||||
|
#set to defualt
|
||||||
|
self.card_id.value = ''
|
||||||
|
self.card_id.update()
|
||||||
|
self.card_type.value = ''
|
||||||
|
self.card_type.update()
|
||||||
|
self.client_name.value = ''
|
||||||
|
self.client_name.update()
|
||||||
|
self.phone_number.value = ''
|
||||||
|
self.phone_number.update()
|
||||||
|
|
||||||
|
#close popup
|
||||||
|
self.page.close(self.add_dialog)
|
||||||
|
|
||||||
|
#update_list
|
||||||
|
self.update_list()
|
||||||
|
|
||||||
|
def update_list(self):
|
||||||
|
self.all_cards = self.fidelity_cards_manager.get_all_fidelity_cards()
|
||||||
|
self.list_of_cars.controls = self.create_list(
|
||||||
|
self.all_cards,
|
||||||
|
self.on_delete_btn_click,
|
||||||
|
self.on_edit_btn_click
|
||||||
|
)
|
||||||
|
self.list_of_cars.update()
|
||||||
|
|
||||||
|
def on_cancel_btn_click(self, e):
|
||||||
|
self.page.close(self.add_dialog)
|
||||||
|
self.item_to_be_edit = None
|
||||||
|
|
||||||
|
def on_add_btn_click(self, e):
|
||||||
|
self.page.open(self.add_dialog)
|
||||||
|
|
||||||
|
def create_list(self, items, on_click_handler2, on_click_handler3):
|
||||||
|
return [
|
||||||
|
ft.Container(
|
||||||
|
content=ft.Row(
|
||||||
|
[
|
||||||
|
|
||||||
|
ft.Column(
|
||||||
|
[
|
||||||
|
ft.Text(value=f"Nume: {item['client_name']}", weight=ft.FontWeight.BOLD),
|
||||||
|
ft.Row(
|
||||||
|
[
|
||||||
|
ft.Text(value=f"Id card: {item['card_id']};", size=12),
|
||||||
|
ft.Text(value=f"Reducere: {item['card_type']}%;", size=12),
|
||||||
|
ft.Text(value=f"Telefon: {item['phone_number']}%", size=12)
|
||||||
|
],
|
||||||
|
spacing=10
|
||||||
|
)
|
||||||
|
]
|
||||||
|
),
|
||||||
|
|
||||||
|
ft.Row(
|
||||||
|
[
|
||||||
|
ft.IconButton(
|
||||||
|
icon=ft.Icons.EDIT,
|
||||||
|
on_click=lambda e, id=item: on_click_handler3(id),
|
||||||
|
),
|
||||||
|
ft.IconButton(
|
||||||
|
icon=ft.Icons.DELETE,
|
||||||
|
on_click=lambda e, id=item['id']: on_click_handler2(id),
|
||||||
|
icon_color=ft.Colors.RED,
|
||||||
|
),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
],
|
||||||
|
alignment=ft.MainAxisAlignment.SPACE_BETWEEN,
|
||||||
|
),
|
||||||
|
width=300,
|
||||||
|
bgcolor=ft.Colors.BROWN_50,
|
||||||
|
border = ft.border.all(1, ft.Colors.GREY),
|
||||||
|
padding=10,
|
||||||
|
border_radius=8,
|
||||||
|
)
|
||||||
|
for item in items
|
||||||
|
]
|
||||||
|
|
||||||
|
def on_search_btn_click(self, e):
|
||||||
|
print(self.search_bar.value)
|
||||||
|
|
||||||
|
for card in self.all_cards:
|
||||||
|
buffer = []
|
||||||
|
if self.search_bar.value in card['phone_number']:
|
||||||
|
buffer.append(card)
|
||||||
|
self.list_of_cars.controls = self.create_list(
|
||||||
|
buffer,
|
||||||
|
self.on_delete_btn_click,
|
||||||
|
self.on_edit_btn_click
|
||||||
|
)
|
||||||
|
self.list_of_cars.update()
|
||||||
|
|
||||||
|
#set to default
|
||||||
|
self.search_bar.value = ''
|
||||||
|
self.search_bar.update()
|
||||||
|
|
||||||
|
def on_delete_btn_click(self, id):
|
||||||
|
self.item_to_be_delete = id
|
||||||
|
self.page.open(self.delete_dialog)
|
||||||
|
|
||||||
|
def on_edit_btn_click(self, item):
|
||||||
|
self.page.open(self.add_dialog)
|
||||||
|
self.item_to_be_edit = item['id']
|
||||||
|
self.card_id.value = item['card_id']
|
||||||
|
self.card_id.update()
|
||||||
|
self.card_type.value = item['card_type']
|
||||||
|
self.card_type.update()
|
||||||
|
self.client_name.value = item['client_name']
|
||||||
|
self.client_name.update()
|
||||||
|
self.phone_number.value = item['phone_number']
|
||||||
|
self.phone_number.update()
|
||||||
|
|
||||||
|
def build(self):
|
||||||
|
return ft.Container(
|
||||||
|
content=ft.Column(
|
||||||
|
[
|
||||||
|
ft.Row(
|
||||||
|
[
|
||||||
|
ft.Text("Card de fidelitate", size=18, weight=ft.FontWeight.BOLD),
|
||||||
|
ft.Button("Adauga", icon=ft.Icons.ADD, on_click=self.on_add_btn_click),
|
||||||
|
],
|
||||||
|
alignment=ft.MainAxisAlignment.SPACE_BETWEEN
|
||||||
|
),
|
||||||
|
ft.Row(
|
||||||
|
[
|
||||||
|
self.search_bar,
|
||||||
|
self.search_btn
|
||||||
|
]
|
||||||
|
),
|
||||||
|
self.list_of_cars
|
||||||
|
],
|
||||||
|
alignment=ft.MainAxisAlignment.START,
|
||||||
|
expand=True
|
||||||
|
),
|
||||||
|
expand=True
|
||||||
|
)
|
||||||
@@ -3,6 +3,7 @@ from dbActions.orders import Orders
|
|||||||
from dbActions.users import Users
|
from dbActions.users import Users
|
||||||
from dbActions.products import Products
|
from dbActions.products import Products
|
||||||
from helpers.default_user import DefaultUser
|
from helpers.default_user import DefaultUser
|
||||||
|
from helpers.emails import send_gmail
|
||||||
|
|
||||||
class OrdersPage:
|
class OrdersPage:
|
||||||
def __init__(self, page: ft.Page):
|
def __init__(self, page: ft.Page):
|
||||||
@@ -190,12 +191,22 @@ class OrdersPage:
|
|||||||
self.oll_orders_list.update()
|
self.oll_orders_list.update()
|
||||||
self.order_details_placeholder.content = None
|
self.order_details_placeholder.content = None
|
||||||
self.order_details_placeholder.update()
|
self.order_details_placeholder.update()
|
||||||
#-------------------------------------------> TBI Send information email to customer
|
|
||||||
message = self.message_field.value
|
message = self.message_field.value
|
||||||
self.message_field.value = ''
|
self.message_field.value = ''
|
||||||
self.message_field.update()
|
self.message_field.update()
|
||||||
print(message)
|
print(message)
|
||||||
email = self.customer_email
|
email = self.customer_email
|
||||||
|
status_values = {
|
||||||
|
"on_hold":"in asteptare",
|
||||||
|
"new": "noua",
|
||||||
|
"in_progress":"in lucru",
|
||||||
|
"completed": "la curier",
|
||||||
|
}
|
||||||
|
send_gmail(
|
||||||
|
to_email=email,
|
||||||
|
subject=f"Comanda cumneavoastra este: {status_values[status]}",
|
||||||
|
body=message
|
||||||
|
)
|
||||||
|
|
||||||
def on_cancel_state_btn_click(self, e):
|
def on_cancel_state_btn_click(self, e):
|
||||||
self.buttons_state.value = self.original_status
|
self.buttons_state.value = self.original_status
|
||||||
@@ -230,9 +241,10 @@ class OrdersPage:
|
|||||||
if products:
|
if products:
|
||||||
for product in products:
|
for product in products:
|
||||||
prod = self.products.get(product['prdouct_id'])
|
prod = self.products.get(product['prdouct_id'])
|
||||||
print(prod)
|
|
||||||
if prod:
|
if prod:
|
||||||
|
prod['pices'] = product['quantity']
|
||||||
self.selected_order_products.append(prod)
|
self.selected_order_products.append(prod)
|
||||||
|
print(prod)
|
||||||
|
|
||||||
self.name.value = self.selected_user['name'] if '@default.com' not in self.selected_user['email'] else 'Anonim user'
|
self.name.value = self.selected_user['name'] if '@default.com' not in self.selected_user['email'] else 'Anonim user'
|
||||||
self.name.update()
|
self.name.update()
|
||||||
@@ -259,17 +271,29 @@ class OrdersPage:
|
|||||||
)
|
)
|
||||||
image = ft.Image(
|
image = ft.Image(
|
||||||
src=product['image'],
|
src=product['image'],
|
||||||
width=200,
|
width=120,
|
||||||
height=200,
|
height=120,
|
||||||
fit=ft.ImageFit.CONTAIN
|
fit=ft.ImageFit.CONTAIN
|
||||||
)
|
)
|
||||||
quantity_label = ft.Text("Cantitate")
|
quantity_label = ft.Text("Cantitate")
|
||||||
quantity = ft.Text(product['quantity'])
|
quantity = ft.Text(product['quantity'])
|
||||||
quantity_row = ft.Row(
|
pices_label = ft.Text("Numar bucati")
|
||||||
|
pices = ft.Text(product['pices'])
|
||||||
|
quantity_row = ft.Column(
|
||||||
|
[
|
||||||
|
ft.Row(
|
||||||
[
|
[
|
||||||
quantity_label,
|
quantity_label,
|
||||||
quantity
|
quantity
|
||||||
]
|
]
|
||||||
|
),
|
||||||
|
ft.Row(
|
||||||
|
[
|
||||||
|
pices_label,
|
||||||
|
pices
|
||||||
|
]
|
||||||
|
)
|
||||||
|
]
|
||||||
)
|
)
|
||||||
product_row = ft.Row(
|
product_row = ft.Row(
|
||||||
[
|
[
|
||||||
|
|||||||
99
UI_V2/dbActions/fidelity_cards.py
Normal file
99
UI_V2/dbActions/fidelity_cards.py
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
import sqlite3
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
class FidelityCards:
|
||||||
|
def __init__(self, db_path="instance/app_database.db"):
|
||||||
|
self.db_path = db_path
|
||||||
|
self._create_fidelity_cards_table()
|
||||||
|
|
||||||
|
def _create_fidelity_cards_table(self):
|
||||||
|
with sqlite3.connect(self.db_path) as conn:
|
||||||
|
cursor = conn.cursor()
|
||||||
|
cursor.execute("""
|
||||||
|
CREATE TABLE IF NOT EXISTS fidelity_cards (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
card_id TEXT,
|
||||||
|
card_type INTEGER,
|
||||||
|
client_name TEXT,
|
||||||
|
phone_number TEXT,
|
||||||
|
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||||
|
);
|
||||||
|
""")
|
||||||
|
conn.commit()
|
||||||
|
|
||||||
|
def add_fidelity_card(self, card_id, card_type, client_name, phone_number):
|
||||||
|
try:
|
||||||
|
with sqlite3.connect(self.db_path) as conn:
|
||||||
|
cursor = conn.cursor()
|
||||||
|
cursor.execute("""
|
||||||
|
INSERT INTO fidelity_cards (card_id, card_type, client_name, phone_number)
|
||||||
|
VALUES (?, ?, ?, ?)
|
||||||
|
""", (card_id, card_type, client_name, phone_number,))
|
||||||
|
conn.commit()
|
||||||
|
return True
|
||||||
|
except sqlite3.IntegrityError:
|
||||||
|
return False
|
||||||
|
|
||||||
|
def get_all_fidelity_cards(self):
|
||||||
|
with sqlite3.connect(self.db_path) as conn:
|
||||||
|
cursor = conn.cursor()
|
||||||
|
cursor.execute("""
|
||||||
|
SELECT * FROM fidelity_cards
|
||||||
|
""",)
|
||||||
|
rows = cursor.fetchall()
|
||||||
|
result = []
|
||||||
|
if rows:
|
||||||
|
for row in rows:
|
||||||
|
buffer = {
|
||||||
|
"id": row[0],
|
||||||
|
"card_id": row[1],
|
||||||
|
"card_type": row[2],
|
||||||
|
"client_name": row[3],
|
||||||
|
"phone_number": row[4],
|
||||||
|
"created_at": row[5]
|
||||||
|
}
|
||||||
|
result.append(buffer)
|
||||||
|
return result
|
||||||
|
return []
|
||||||
|
|
||||||
|
def get_fidelity_card(self, id):
|
||||||
|
with sqlite3.connect(self.db_path) as conn:
|
||||||
|
cursor = conn.cursor()
|
||||||
|
cursor.execute("""
|
||||||
|
SELECT * FROM fidelity_cards WHERE id = ?
|
||||||
|
""",(id, ))
|
||||||
|
row = cursor.fetchone()
|
||||||
|
result = []
|
||||||
|
if row:
|
||||||
|
result = {
|
||||||
|
"id": row[0],
|
||||||
|
"card_id": row[1],
|
||||||
|
"card_type": row[2],
|
||||||
|
"client_name": row[3],
|
||||||
|
"phone_number": row[4],
|
||||||
|
"created_at": row[5]
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
return None
|
||||||
|
|
||||||
|
def remove_fidelity_card(self, id):
|
||||||
|
with sqlite3.connect(self.db_path) as conn:
|
||||||
|
cursor = conn.cursor()
|
||||||
|
cursor.execute('''
|
||||||
|
DELETE FROM fidelity_cards WHERE id=?;
|
||||||
|
''', (id,))
|
||||||
|
conn.commit()
|
||||||
|
|
||||||
|
def update_card(self, id, card_id, card_type, client_name, phone_number):
|
||||||
|
try:
|
||||||
|
with sqlite3.connect(self.db_path) as conn:
|
||||||
|
cursor = conn.cursor()
|
||||||
|
cursor.execute("""
|
||||||
|
UPDATE fidelity_cards
|
||||||
|
SET card_id = ?, card_type = ?, client_name = ?, phone_number = ?
|
||||||
|
WHERE id = ?
|
||||||
|
""", (card_id, card_type, client_name, phone_number, id))
|
||||||
|
conn.commit()
|
||||||
|
return True
|
||||||
|
except Exception:
|
||||||
|
return False
|
||||||
@@ -86,6 +86,15 @@ class Orders:
|
|||||||
''', (status, id))
|
''', (status, id))
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
|
def update_order_user_id(self, user_id, id):
|
||||||
|
with sqlite3.connect(self.db_path) as conn:
|
||||||
|
cursor = conn.cursor()
|
||||||
|
cursor.execute('''
|
||||||
|
UPDATE orders SET user_id = ?
|
||||||
|
WHERE id = ?
|
||||||
|
''', (user_id, id))
|
||||||
|
conn.commit()
|
||||||
|
|
||||||
def get_order_products(self, id):
|
def get_order_products(self, id):
|
||||||
with sqlite3.connect(self.db_path) as conn:
|
with sqlite3.connect(self.db_path) as conn:
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
|
|||||||
@@ -3,19 +3,21 @@ from dbActions.orders import Orders
|
|||||||
from dbActions.products import Products
|
from dbActions.products import Products
|
||||||
from dbActions.company import Company
|
from dbActions.company import Company
|
||||||
from dbActions.users import Users
|
from dbActions.users import Users
|
||||||
|
from helpers.emails import send_gmail
|
||||||
|
import re
|
||||||
|
|
||||||
class Cart:
|
class Cart:
|
||||||
def __init__(self, page: ft.Page):
|
def __init__(self, page: ft.Page):
|
||||||
self.page = page
|
self.page = page
|
||||||
self.user = self.page.session.get('user')
|
self.user = self.page.session.get('user')
|
||||||
self.orders = Orders()
|
self.orders_manager = Orders()
|
||||||
self.productsDB = Products()
|
self.productsDB = Products()
|
||||||
self.company_manager = Company()
|
self.company_manager = Company()
|
||||||
self.user_manager = Users()
|
self.user_manager = Users()
|
||||||
self.products = []
|
self.products = []
|
||||||
self.is_second_address = None
|
self.is_second_address = None
|
||||||
self.is_company = None
|
self.is_company = None
|
||||||
|
self.pret_total = ft.Text("Pret total: 0", weight=ft.FontWeight.BOLD)
|
||||||
self.delete_dialog = ft.AlertDialog(
|
self.delete_dialog = ft.AlertDialog(
|
||||||
title=ft.Text("Stergeti?"),
|
title=ft.Text("Stergeti?"),
|
||||||
actions=[
|
actions=[
|
||||||
@@ -24,9 +26,9 @@ class Cart:
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
self.on_hold_orders = self.orders.get_on_hold_order(self.user['id'])
|
self.on_hold_orders = self.orders_manager.get_on_hold_order(self.user['id'])
|
||||||
if self.on_hold_orders:
|
if self.on_hold_orders:
|
||||||
self.order_products = self.orders.get_order_products(self.on_hold_orders['id'])
|
self.order_products = self.orders_manager.get_order_products(self.on_hold_orders['id'])
|
||||||
|
|
||||||
for product in self.order_products:
|
for product in self.order_products:
|
||||||
self.products.append(
|
self.products.append(
|
||||||
@@ -70,10 +72,9 @@ class Cart:
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
if '@default.com' not in self.user['email']:
|
self.all_orders = self.orders_manager.get_orders_for_user(self.page.session.get('user')['id'])
|
||||||
self.all_orders = self.orders.get_orders_for_user(self.page.session.get('user')['id'])
|
|
||||||
self.all_orders = self.all_orders[::-1]
|
self.all_orders = self.all_orders[::-1]
|
||||||
self.orders_list = ft.ListView(
|
self.orders_manager_list = ft.ListView(
|
||||||
controls=self.create_history_list(self.all_orders),
|
controls=self.create_history_list(self.all_orders),
|
||||||
spacing=10,
|
spacing=10,
|
||||||
expand=True
|
expand=True
|
||||||
@@ -87,7 +88,7 @@ class Cart:
|
|||||||
self.email = ft.TextField(
|
self.email = ft.TextField(
|
||||||
label="E-mail",
|
label="E-mail",
|
||||||
value=self.user['email'] if "@default.com" not in self.user['email'] else None,
|
value=self.user['email'] if "@default.com" not in self.user['email'] else None,
|
||||||
read_only=True
|
read_only=True if "@default.com" not in self.user['email'] else False
|
||||||
)
|
)
|
||||||
self.phone = ft.TextField(
|
self.phone = ft.TextField(
|
||||||
label="Telefon",
|
label="Telefon",
|
||||||
@@ -195,14 +196,7 @@ class Cart:
|
|||||||
vertical_alignment=ft.CrossAxisAlignment.START
|
vertical_alignment=ft.CrossAxisAlignment.START
|
||||||
)
|
)
|
||||||
self.order_list_placeholder = ft.Column()
|
self.order_list_placeholder = ft.Column()
|
||||||
if '@default.com' not in self.user['email']:
|
self.order_list_placeholder.controls.append(self.orders_manager_list)
|
||||||
self.order_list_placeholder.controls.append(
|
|
||||||
ft.Text(
|
|
||||||
"Istoric comenzi",
|
|
||||||
weight=ft.FontWeight.BOLD
|
|
||||||
)
|
|
||||||
)
|
|
||||||
self.order_list_placeholder.controls.append(self.orders_list)
|
|
||||||
|
|
||||||
self.item_to_be_deleted = None
|
self.item_to_be_deleted = None
|
||||||
|
|
||||||
@@ -229,17 +223,27 @@ class Cart:
|
|||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def order_products(self, id):
|
def get_order_products(self, id):
|
||||||
products = self.orders.get_order_products(id)
|
products = self.orders_manager.get_order_products(id)
|
||||||
|
total = 0
|
||||||
|
|
||||||
all_products = []
|
all_products = []
|
||||||
for product in products:
|
for product in products:
|
||||||
name = self.productsDB.get(product['prdouct_id'])['name']
|
item = self.productsDB.get(product['prdouct_id'])
|
||||||
|
total += item['price']
|
||||||
|
name = item['name']
|
||||||
if name not in all_products:
|
if name not in all_products:
|
||||||
all_products.append(name)
|
all_products.append(name)
|
||||||
|
try:
|
||||||
|
self.pret_total.value = f'Pret total: {total}'
|
||||||
|
self.pret_total.update()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
return ft.Text(
|
return ft.Text(
|
||||||
value=' '.join(all_products)
|
value=' '.join(all_products)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def on_go_back_button_click(self, e):
|
def on_go_back_button_click(self, e):
|
||||||
self.page.go("/")
|
self.page.go("/")
|
||||||
|
|
||||||
@@ -296,6 +300,12 @@ class Cart:
|
|||||||
]
|
]
|
||||||
|
|
||||||
def create_history_list(self, items):
|
def create_history_list(self, items):
|
||||||
|
status_value = {
|
||||||
|
'new':'Noua',
|
||||||
|
'on_hold':'In asteptare',
|
||||||
|
'in_progress': 'In lucru',
|
||||||
|
'completed':'Complete'
|
||||||
|
}
|
||||||
return [
|
return [
|
||||||
ft.Container(
|
ft.Container(
|
||||||
content=ft.Column(
|
content=ft.Column(
|
||||||
@@ -303,7 +313,7 @@ class Cart:
|
|||||||
|
|
||||||
ft.Row(
|
ft.Row(
|
||||||
[
|
[
|
||||||
ft.Icon(ft.icons.ARROW_RIGHT, size=20),
|
ft.Icon(ft.Icons.ARROW_RIGHT, size=20),
|
||||||
ft.Text(value="Numar comanda: "),
|
ft.Text(value="Numar comanda: "),
|
||||||
ft.Text(value=item['id'])
|
ft.Text(value=item['id'])
|
||||||
]
|
]
|
||||||
@@ -314,7 +324,7 @@ class Cart:
|
|||||||
value='Status: '
|
value='Status: '
|
||||||
),
|
),
|
||||||
ft.Text(
|
ft.Text(
|
||||||
value=item['status']
|
value=status_value[item['status']]
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
@@ -323,7 +333,7 @@ class Cart:
|
|||||||
ft.Text(
|
ft.Text(
|
||||||
value='Produse: '
|
value='Produse: '
|
||||||
),
|
),
|
||||||
#self.order_products(item['id'])
|
self.get_order_products(item['id'])
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
@@ -338,7 +348,6 @@ class Cart:
|
|||||||
for item in items
|
for item in items
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def on_delete_product_click(self, item):
|
def on_delete_product_click(self, item):
|
||||||
print('Delte item', item)
|
print('Delte item', item)
|
||||||
|
|
||||||
@@ -349,9 +358,9 @@ class Cart:
|
|||||||
def on_confirm_delete_btn_click(self, e):
|
def on_confirm_delete_btn_click(self, e):
|
||||||
print("confirm delete item", self.item_to_be_deleted)
|
print("confirm delete item", self.item_to_be_deleted)
|
||||||
#remove item
|
#remove item
|
||||||
self.orders.remove_product_from_order(self.on_hold_orders['id'], self.item_to_be_deleted)
|
self.orders_manager.remove_product_from_order(self.on_hold_orders['id'], self.item_to_be_deleted)
|
||||||
#update list
|
#update list
|
||||||
self.order_products = self.orders.get_order_products(self.on_hold_orders['id'])
|
self.order_products = self.orders_manager.get_order_products(self.on_hold_orders['id'])
|
||||||
self.products = []
|
self.products = []
|
||||||
for product in self.order_products:
|
for product in self.order_products:
|
||||||
self.products.append(
|
self.products.append(
|
||||||
@@ -372,7 +381,6 @@ class Cart:
|
|||||||
self.item_to_be_deleted = None
|
self.item_to_be_deleted = None
|
||||||
self.page.close(self.delete_dialog)
|
self.page.close(self.delete_dialog)
|
||||||
|
|
||||||
|
|
||||||
def open_confirm_dialog(self, e):
|
def open_confirm_dialog(self, e):
|
||||||
print('open dialog')
|
print('open dialog')
|
||||||
print(self.on_hold_orders)
|
print(self.on_hold_orders)
|
||||||
@@ -392,18 +400,24 @@ class Cart:
|
|||||||
self.error_message.value = "Va rugam inserati adresa de livrare!"
|
self.error_message.value = "Va rugam inserati adresa de livrare!"
|
||||||
self.error_message.color = ft.Colors.RED
|
self.error_message.color = ft.Colors.RED
|
||||||
self.error_message.update()
|
self.error_message.update()
|
||||||
|
print('Second address found')
|
||||||
return True
|
return True
|
||||||
|
print('Second address not found')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def check_company_data_inserted(self, company_name, vat, register_number, company_address):
|
def check_company_data_inserted(self, company_name, vat, register_number, company_address):
|
||||||
found = False
|
found = False
|
||||||
if company_name is None or len(company_name)< 1:
|
if company_name is None or len(company_name)< 1:
|
||||||
|
print("Comapny name not found")
|
||||||
found = True
|
found = True
|
||||||
if vat is None or len(vat)< 1:
|
if vat is None or len(vat)< 1:
|
||||||
|
print("Vat not found")
|
||||||
found = True
|
found = True
|
||||||
if register_number is None or len(register_number)< 1:
|
if register_number is None or len(register_number)< 1:
|
||||||
|
print("Register number not found")
|
||||||
found = True
|
found = True
|
||||||
if company_address is None or len(company_address)< 1:
|
if company_address is None or len(company_address)< 1:
|
||||||
|
print("Company address not found")
|
||||||
found = True
|
found = True
|
||||||
if found:
|
if found:
|
||||||
self.error_message.value = "Toate campurile sunt obligatori!"
|
self.error_message.value = "Toate campurile sunt obligatori!"
|
||||||
@@ -411,13 +425,19 @@ class Cart:
|
|||||||
self.error_message.update()
|
self.error_message.update()
|
||||||
return found
|
return found
|
||||||
|
|
||||||
def check_inserted_user_data(self, username, phone, address):
|
def check_inserted_user_data(self, username, phone, address, email):
|
||||||
found = False
|
found = False
|
||||||
if username is None or len(username)< 1:
|
if username is None or len(username)< 1:
|
||||||
|
print('Username not found')
|
||||||
found = True
|
found = True
|
||||||
if phone is None or len(phone)< 1:
|
if phone is None or len(phone)< 1:
|
||||||
|
print("Phone not found")
|
||||||
found = True
|
found = True
|
||||||
if address is None or len(address)< 1:
|
if address is None or len(address)< 1:
|
||||||
|
print("Adress not found")
|
||||||
|
found = True
|
||||||
|
if email is None or len(email)<1:
|
||||||
|
print("email not found")
|
||||||
found = True
|
found = True
|
||||||
if found:
|
if found:
|
||||||
self.error_message.value = "Toate campurile sunt obligatori!"
|
self.error_message.value = "Toate campurile sunt obligatori!"
|
||||||
@@ -426,25 +446,53 @@ class Cart:
|
|||||||
|
|
||||||
return found
|
return found
|
||||||
|
|
||||||
|
def check_email_is_valid(self, email):
|
||||||
|
email_regex = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'
|
||||||
|
if re.fullmatch(email_regex, email) is not None:
|
||||||
|
self.error_message.value = ""
|
||||||
|
self.error_message.update()
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
self.error_message.value = "Va rugam inserati un e-mail valid!"
|
||||||
|
self.error_message.update()
|
||||||
|
return False
|
||||||
|
|
||||||
def create_update_user_details(self):
|
def create_update_user_details(self):
|
||||||
username = self.user_name.value
|
username = self.user_name.value
|
||||||
phone = self.phone.value
|
phone = self.phone.value
|
||||||
address = self.address.value
|
address = self.address.value
|
||||||
|
email = self.email.value
|
||||||
|
|
||||||
if self.is_second_address:
|
if self.is_second_address:
|
||||||
|
print("Second address has been selected (button click)")
|
||||||
if self.check_second_address_inserted(self.second_address.value):
|
if self.check_second_address_inserted(self.second_address.value):
|
||||||
return
|
return False
|
||||||
address = self.address.value + '~' + self.second_address.value
|
address = self.address.value + '~' + self.second_address.value
|
||||||
if self.check_inserted_user_data(username, phone, address):
|
if self.check_inserted_user_data(username, phone, address, email):
|
||||||
return
|
return False
|
||||||
|
|
||||||
|
if not self.check_email_is_valid(email):
|
||||||
|
return False
|
||||||
|
|
||||||
if '@default.com' in self.user['email']:
|
if '@default.com' in self.user['email']:
|
||||||
self.user = self.user_manager.invite_user()
|
print("User is default @default.com in name")
|
||||||
|
try:
|
||||||
|
user_id = self.user_manager.invite_user(
|
||||||
|
email, username, phone, address
|
||||||
|
)
|
||||||
|
self.user = self.user_manager.get(user_id)
|
||||||
|
print("User invited")
|
||||||
self.page.session.set("user", self.user)
|
self.page.session.set("user", self.user)
|
||||||
|
self.orders_manager.update_order_user_id(user_id, self.on_hold_orders['id'])
|
||||||
|
except:
|
||||||
|
print("Unable to create user, user already exists")
|
||||||
|
self.error_message.value = "Exita deja un utilizator cu aceasta adresa de email!"
|
||||||
|
return False
|
||||||
else:
|
else:
|
||||||
self.user_manager.update_user_data(username, phone, address, self.user['id'])
|
self.user_manager.update_user_data(username, phone, address, self.user['id'])
|
||||||
|
|
||||||
if self.is_company:
|
if self.is_company:
|
||||||
|
print("Compani selected (company button has been pressed)")
|
||||||
if self.check_company_data_inserted(self.company_name.value, self.vat.value, self.register_number.value, self.company_address.value):
|
if self.check_company_data_inserted(self.company_name.value, self.vat.value, self.register_number.value, self.company_address.value):
|
||||||
return
|
return
|
||||||
if self.company:
|
if self.company:
|
||||||
@@ -462,19 +510,23 @@ class Cart:
|
|||||||
'address': self.company_address.value
|
'address': self.company_address.value
|
||||||
}
|
}
|
||||||
self.company_manager.add_company(company)
|
self.company_manager.add_company(company)
|
||||||
|
return True
|
||||||
|
|
||||||
def on_confim_btn_click(self, e):
|
def on_confim_btn_click(self, e):
|
||||||
|
self.error_message.color = ft.Colors.RED
|
||||||
|
self.error_message.update()
|
||||||
#create / update user details:
|
#create / update user details:
|
||||||
self.create_update_user_details()
|
print("Confirm button Selected ")
|
||||||
|
|
||||||
print('confirm')
|
|
||||||
self.page.close(self.confirm_dialog)
|
self.page.close(self.confirm_dialog)
|
||||||
self.orders.update_order_status("new", self.on_hold_orders['id'])
|
if self.create_update_user_details():
|
||||||
|
print('User details updated')
|
||||||
|
|
||||||
|
self.orders_manager.update_order_status("new", self.on_hold_orders['id'])
|
||||||
|
print('Order status is set to new')
|
||||||
self.products = []
|
self.products = []
|
||||||
self.on_hold_orders = self.orders.get_on_hold_order(self.user['id'])
|
self.on_hold_orders = self.orders_manager.get_on_hold_order(self.user['id'])
|
||||||
if self.on_hold_orders:
|
if self.on_hold_orders:
|
||||||
self.order_products = self.orders.get_order_products(self.on_hold_orders['id'])
|
self.order_products = self.orders_manager.get_order_products(self.on_hold_orders['id'])
|
||||||
|
|
||||||
for product in self.order_products:
|
for product in self.order_products:
|
||||||
self.products.append(
|
self.products.append(
|
||||||
@@ -486,12 +538,47 @@ class Cart:
|
|||||||
self.product_list.controls.clear()
|
self.product_list.controls.clear()
|
||||||
self.product_list.controls = self.create_list(self.products, self.on_delete_product_click)
|
self.product_list.controls = self.create_list(self.products, self.on_delete_product_click)
|
||||||
self.product_list.update()
|
self.product_list.update()
|
||||||
|
|
||||||
|
#hiostory
|
||||||
if '@default.com' not in self.user['email']:
|
if '@default.com' not in self.user['email']:
|
||||||
self.all_orders = self.orders.get_orders_for_user(self.page.session.get('user')['id'])
|
self.all_orders = self.orders_manager.get_orders_for_user(self.page.session.get('user')['id'])
|
||||||
self.all_orders = self.all_orders[::-1]
|
self.all_orders = self.all_orders[::-1]
|
||||||
self.orders_list.controls.clear()
|
self.orders_manager_list.controls.clear()
|
||||||
self.orders_list.controls = self.create_history_list(self.all_orders)
|
self.orders_manager_list.controls = self.create_history_list(self.all_orders)
|
||||||
self.orders_list.update()
|
self.orders_manager_list.update()
|
||||||
|
|
||||||
|
#notify admin
|
||||||
|
users = self.user_manager.get_all()
|
||||||
|
admins = []
|
||||||
|
for user in users:
|
||||||
|
if user['role'] == 'admin':
|
||||||
|
admins.append(user)
|
||||||
|
for admin in admins:
|
||||||
|
send_gmail(
|
||||||
|
to_email=admin['email'],
|
||||||
|
subject="Comanda noua pe tainagustului.ro",
|
||||||
|
body=f'''
|
||||||
|
Ati primit o noua comanda de la {self.user['email']}.
|
||||||
|
Va rugam accesati wwww.tainagusutului.ro pentru detalii.
|
||||||
|
'''
|
||||||
|
)
|
||||||
|
|
||||||
|
send_gmail(
|
||||||
|
to_email=self.user['email'],
|
||||||
|
subject="Multumim pentru comanda!",
|
||||||
|
body=f'''
|
||||||
|
Buna ziua,
|
||||||
|
|
||||||
|
Comanda a fost primita si va fi livrata in cel mai scurt timp.
|
||||||
|
|
||||||
|
Va multumim,
|
||||||
|
Echipa tainagustului.ro
|
||||||
|
'''
|
||||||
|
)
|
||||||
|
|
||||||
|
self.error_message.value = "Comanda a fost trimisa cu success!"
|
||||||
|
self.error_message.color = ft.Colors.GREEN
|
||||||
|
self.error_message.update()
|
||||||
|
|
||||||
def build(self):
|
def build(self):
|
||||||
return ft.Container(
|
return ft.Container(
|
||||||
@@ -505,10 +592,15 @@ class Cart:
|
|||||||
ft.Icons.SHOPPING_CART_CHECKOUT,
|
ft.Icons.SHOPPING_CART_CHECKOUT,
|
||||||
size=40,
|
size=40,
|
||||||
),
|
),
|
||||||
|
ft.Column(
|
||||||
|
[
|
||||||
|
self.pret_total,
|
||||||
ft.Text(
|
ft.Text(
|
||||||
"Produse adugate:",
|
"Produse adugate:",
|
||||||
weight=ft.FontWeight.BOLD,
|
weight=ft.FontWeight.BOLD,
|
||||||
size=15
|
size=15
|
||||||
|
),
|
||||||
|
]
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user