diff --git a/UI_V2/admin/inventory/goods_reception.py b/UI_V2/admin/inventory/goods_reception.py index 265dda5..b4172f0 100644 --- a/UI_V2/admin/inventory/goods_reception.py +++ b/UI_V2/admin/inventory/goods_reception.py @@ -20,9 +20,9 @@ class GoodsReception: expand=True ) self.product_mesure_unit.value = 'kg' - self.product_quantity = ft.TextField(label="Cantitate") - self.product_price = ft.TextField(label="Pret") - self.product_vat = ft.TextField(label="TVA (0 pentru neplatitor de TVA)", value="0") + self.product_quantity = ft.TextField(label="Cantitate (Numar de unitati)") + self.product_price = ft.TextField(label="Pret pe unitate") + self.product_vat = ft.TextField(label="TVA% (0 pentru neplatitor de TVA)", value="0") self.bill_number = ft.TextField(label="Serie si numar") self.bill_date = ft.TextField(label="Data", read_only=True, expand=True) @@ -80,7 +80,8 @@ class GoodsReception: self.all_bills, self.on_add_product_btn_click, self.on_edit_provider_bill_btn_click, - self.on_delete_provider_bill_btn_click + self.on_delete_provider_bill_btn_click, + self.on_view_list_btn_click ), spacing=10, expand=True, @@ -107,15 +108,110 @@ class GoodsReception: self.edit_item = None - self.placeholder = ft.Column() - - self.add_group = ft.Row( - self.product_name, - self.product_quantity, - self.product_mesure_unit, - self.product_quantity, + self.add_product_dialog = ft.AlertDialog( + title=ft.Text("Adauga produs"), + content=ft.Column( + [ + self.product_name, + self.product_quantity, + self.product_mesure_unit, + self.product_price, + self.product_vat + ], + width=400, + height=300 + ), + actions=[ + ft.Button( + "Salveaza", + icon=ft.Icons.SAVE, + on_click=self.on_save_product_btn_click + ), + ft.TextButton( + "Anuleaza", + on_click=self.on_cancel_product_btn_click + ) + ] ) + self.selected_bill = None + + self.products_table = ft.DataTable( + columns=[ + ft.DataColumn(ft.Text("Produs")), + ft.DataColumn(ft.Text("Cantitate")), + ft.DataColumn(ft.Text("Unitate\nde masura")), + ft.DataColumn(ft.Text("Pret\nfara TVA")), + ft.DataColumn(ft.Text("Procent\nTVA(%)")), + ft.DataColumn(ft.Text("Pret\nproduse")), + ft.DataColumn(ft.Text("Valoare\nTVA")), + ft.DataColumn(ft.Text("Pret\nfinal")), + ], + rows=[] + ) + + self.placeholder = ft.Column([self.products_table]) + + def show_bill_products(self): + all_products = self.bulk_products_manager.get_products_by_bill_id(self.selected_bill['id'])[::-1] + print(all_products) + self.products_table.rows.clear() + for product in all_products: + print(product) + price = round((product['price']*product['quantity'])*product['vat']/100+(product['price']*product['quantity']),2) + product_price = product['price']*product['quantity'] + vat_value = (product['price']*product['quantity'])*product['vat']/100 + self.products_table.rows.append( + ft.DataRow( + cells=[ + ft.DataCell(ft.Text(product['name'])), + ft.DataCell(ft.Text(product['quantity'])), + ft.DataCell(ft.Text(product['mesure_unit'])), + ft.DataCell(ft.Text(product['price'])), + ft.DataCell(ft.Text(product['vat'])), + ft.DataCell(ft.Text(product_price)), + ft.DataCell(ft.Text(vat_value)), + ft.DataCell(ft.Text(price)), + ], + ) + ) + self.products_table.update() + + def on_save_product_btn_click(self, e): + name = self.product_name.value + quantity = self.product_quantity.value + mesure_unit = self.product_mesure_unit.value + price = self.product_price.value + vat = self.product_vat.value + self.bulk_products_manager.add_bulk_products_product( + bill_id=self.selected_bill['id'], + name=name, + mesure_unit=mesure_unit, + quantity=quantity, + price=price, + vat=vat + ) + self.reset_values() + self.page.close(self.add_product_dialog) + self.show_bill_products() + + def on_cancel_product_btn_click(self, e): + self.reset_values() + self.page.close(self.add_product_dialog) + + def reset_values(self): + self.product_name.value = '' + self.product_name.update() + self.product_quantity.value = '' + self.product_quantity.update() + self.product_mesure_unit.value = 'kg' + self.product_mesure_unit.update() + self.product_price.value = '' + self.product_price.update() + self.product_vat.value = '0' + self.product_vat.update() + + def on_confirm_delete_bill_btn_click(self, e): self.page.close(self.delete_bill_dialog) self.bill_manager.remove(self.delete_item_id) @@ -128,8 +224,13 @@ class GoodsReception: self.delete_item_id = None def on_add_product_btn_click(self, item): + self.selected_bill = item self.page.open(self.add_product_dialog) + def on_view_list_btn_click(self, item): + self.selected_bill = item + self.show_bill_products() + def on_edit_provider_bill_btn_click(self, item): self.edit_item = item self.bill_number.value = item['number'] @@ -147,7 +248,7 @@ class GoodsReception: if provider['id'] == id: return provider['provider_name'] - def create_bill_list(self, items, on_click_handler, on_click_handler2, on_click_handler3): + def create_bill_list(self, items, on_click_handler, on_click_handler2, on_click_handler3, on_click_handler4): """Helper to create list items for a column.""" return [ ft.Container( @@ -171,6 +272,10 @@ class GoodsReception: ), ft.Row( [ + ft.IconButton( + icon=ft.Icons.PREVIEW, + on_click=lambda e, id=item: on_click_handler4(id) + ), ft.IconButton( icon=ft.Icons.EDIT, on_click=lambda e, id=item: on_click_handler2(id), @@ -179,7 +284,7 @@ class GoodsReception: icon=ft.Icons.DELETE, on_click=lambda e, id=item['id']: on_click_handler3(id), icon_color=ft.Colors.RED, - ), + ) ], alignment=ft.MainAxisAlignment.SPACE_BETWEEN, expand=True @@ -260,7 +365,8 @@ class GoodsReception: list_value, self.on_add_product_btn_click, self.on_edit_provider_bill_btn_click, - self.on_delete_provider_bill_btn_click + self.on_delete_provider_bill_btn_click, + self.on_view_list_btn_click ) self.bills_list.update() @@ -285,7 +391,8 @@ class GoodsReception: [ self.bills_list, self.placeholder - ] + ], + vertical_alignment=ft.CrossAxisAlignment.START ) ] ) diff --git a/UI_V2/admin/orders.py b/UI_V2/admin/orders.py index 73fdfc2..cb863a1 100644 --- a/UI_V2/admin/orders.py +++ b/UI_V2/admin/orders.py @@ -306,6 +306,7 @@ class OrdersPage: self.phone.update() self.status.value = self.selected_user['status'] self.status.update() + #self.date.value = item[''] for product in self.selected_order_products: name_label = ft.Text( "Denumire produs", diff --git a/UI_V2/dbActions/bulk_products.py b/UI_V2/dbActions/bulk_products.py index 0894f16..dc68902 100644 --- a/UI_V2/dbActions/bulk_products.py +++ b/UI_V2/dbActions/bulk_products.py @@ -82,16 +82,17 @@ class BulkProducts: return result return None - def get_product_by_bill_id(self, bill_id): + def get_products_by_bill_id(self, bill_id): with sqlite3.connect(self.db_path) as conn: cursor = conn.cursor() cursor.execute(""" SELECT * FROM bulk_products WHERE bill_id = ? """,(bill_id, )) - row = cursor.fetchone() + rows = cursor.fetchall() result = [] - if row: - result = { + if rows: + for row in rows: + buffer = { "id": row[0], "bill_id": row[1], "name": row[2], @@ -101,8 +102,9 @@ class BulkProducts: "vat": row[6], "created_at": row[7] } + result.append(buffer) return result - return None + return [] def remove(self, id): with sqlite3.connect(self.db_path) as conn: