Github Top Repositories
13.4K subscribers
1.35K photos
58 videos
10 files
1.98K links
Top GitHub repositories in one place 🚀
Explore the best projects in programming, AI, data science, and more.
Download Telegram
# In __init__, call the setup method
self.setup_pos_ui()
self.current_sale_items = {} # Dictionary to store {drug_id: {data, quantity}}

def setup_pos_ui(self):
main_layout = QHBoxLayout()

# Left side: Sale and Barcode input
left_layout = QVBoxLayout()

barcode_group = QGroupBox("Scan Barcode")
barcode_layout = QVBoxLayout()
self.barcode_input = QLineEdit()
self.barcode_input.setPlaceholderText("Scan or type barcode and press Enter...")
self.barcode_input.returnPressed.connect(self.add_item_to_sale)
barcode_layout.addWidget(self.barcode_input)
barcode_group.setLayout(barcode_layout)

self.sales_table = QTableWidget()
self.sales_table.setColumnCount(5)
self.sales_table.setHorizontalHeaderLabels(['ID', 'Name', 'Quantity', 'Unit Price', 'Total Price'])

left_layout.addWidget(barcode_group)
left_layout.addWidget(self.sales_table)

# Right side: Totals and Actions
right_layout = QVBoxLayout()

total_group = QGroupBox("Sale Summary")
total_form = QFormLayout()
self.total_amount_label = QLabel("0.00")
total_form.addRow("Total Amount:", self.total_amount_label)
total_group.setLayout(total_form)

complete_sale_btn = QPushButton("Complete Sale")
complete_sale_btn.clicked.connect(self.complete_sale)
clear_sale_btn = QPushButton("Clear Sale")
clear_sale_btn.clicked.connect(self.clear_sale)

right_layout.addWidget(total_group)
right_layout.addWidget(complete_sale_btn)
right_layout.addWidget(clear_sale_btn)
right_layout.addStretch()

main_layout.addLayout(left_layout, stretch=3) # Left side takes 3/4 of space
main_layout.addLayout(right_layout, stretch=1) # Right side takes 1/4

self.pos_tab.setLayout(main_layout)

#Hashtags: #PointOfSale #BarcodeScanner #UIUX #PyQt5

---

#Step 4: Implementing the Sales Logic

This is the core logic that connects the barcode input to the sales table and the database. When a barcode is entered, we find the drug, add it to the current sale, and update the UI. The "Complete Sale" button will finalize the transaction by updating the database.

Add these methods to the PharmacyApp class: