0% found this document useful (0 votes)
3 views36 pages

Pos Code

The document outlines the code for a Point-of-Sale (POS) system using Visual Basic .NET, which includes the setup of the user interface and dynamic elements such as user login, transaction management, and product catalog. Key components include panels for the header, cart, and product display, as well as buttons for transaction actions. The code also features a method for generating transaction numbers and updating the display clock in real-time.

Uploaded by

arjayrosete918
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views36 pages

Pos Code

The document outlines the code for a Point-of-Sale (POS) system using Visual Basic .NET, which includes the setup of the user interface and dynamic elements such as user login, transaction management, and product catalog. Key components include panels for the header, cart, and product display, as well as buttons for transaction actions. The code also features a method for generating transaction numbers and updating the display clock in real-time.

Uploaded by

arjayrosete918
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Imports [Link].

SqlClient

Imports [Link]

Imports [Link]

Imports [Link]

Imports [Link]

Imports MetroFramework

Public Class POSFORM

Inherits MetroForm

' Dynamically pulls the exact username of the logged-in cashier

Private currentLoggedInUser As String = If(Not


[Link]([Link]),
[Link], "GUEST")

Private pnlTopHeader As Panel

Private pnlLeftCatalog As Panel

Private pnlRightCart As Panel

Private pnlCardWrapper As Panel

Private flpProducts As FlowLayoutPanel

Private dgvCart As DataGridView

Private txtSearch As TextBox

Private cmbCategory As ComboBox

' Summary Labels

Private lblTransNo As Label

Private lblUser As Label

Private lblTotalItemsCount As Label

Private lblTotalQtyCount As Label

Private lblGrandTotalPrice As Label

' Action Buttons


Private btnNewTrans As Button

Private btnSettlePayment As Button

Private btnPending As Button

Private btnVoid As Button

Private btnViewPending As Button

Private btnViewVoid As Button

Private btnTransactionHistory As Button

' Variable to hold the current transaction number format

Private currentTransactionNo As String = ""

' Modern Theme Palette

Private ReadOnly DeepIndigo As Color = [Link](31, 0, 54)

Private ReadOnly ModernBgColor As Color = [Link](248, 250,


252)

Private ReadOnly CardBgColor As Color = [Link]

Private ReadOnly BorderGray As Color = [Link](226, 232, 240)

Private lblLiveClock As Label

Private WithEvents timerClock As New Timer()

Private Sub POSFORM_Load(sender As Object, e As EventArgs) Handles


[Link]

' Fetch the active user dynamically on load

If [Link] IsNot Nothing AndAlso


[Link]() <> "" Then

currentLoggedInUser = [Link]()

Else

currentLoggedInUser = "UNKNOWN CASHIER"

End If

[Link] = [Link]

[Link] = [Link]
[Link] = [Link]

[Link] = "POINT-OF-SALE SYSTEM"

[Link] = New Size(1100, 700)

SetupPOSLayout()

LoadCategories()

LoadProductCatalog("", "All Categories")

GenerateNewTransactionNumber()

End Sub

Private Sub GenerateNewTransactionNumber()

Dim newTransNo As String = "2026-000001"

Using conn As SqlConnection = [Link]()

Try

[Link]()

' Assuming your sales table is named Sales or Transactions and has
a TransactionNo column

Dim query As String = "SELECT TOP 1 TransactionNo FROM


[Link] ORDER BY TransactionID DESC"

Using cmd As New SqlCommand(query, conn)

Dim result = [Link]()

If result IsNot Nothing AndAlso result IsNot [Link] Then

Dim lastNo As String = [Link]()

Dim parts() As String = [Link]("-"c)

If [Link] > 1 AndAlso IsNumeric(parts([Link] - 1))


Then

Dim nextNum As Integer =


Convert.ToInt32(parts([Link] - 1)) + 1

Dim yearPart As String = parts(0) ' Keeps the year prefix


(e.g., 2026)
newTransNo = yearPart & "-" & [Link]("D6")

End If

End If

End Using

Catch ex As Exception

' Fallback if query fails

newTransNo = "2026-" & [Link]("mmssff")

End Try

End Using

currentTransactionNo = newTransNo

[Link] = "Trans No: " & currentTransactionNo

End Sub

Private Sub UpdateClockDisplay()

[Link] = [Link]("MMM dd, yyyy hh:mm:ss


tt")

End Sub

Private Sub SetupPOSLayout()

' 1. Top Modern Header Bar

pnlTopHeader = New Panel()

With pnlTopHeader

.Dock = [Link]

.Height = 115

.BackColor = [Link]

.Padding = New Padding(15)

End With

AddHandler [Link], Sub(s, ev)


[Link]([Link],
[Link], BorderGray, [Link])

End Sub

Dim picLogo As New PictureBox()

With picLogo

.Location = New Point(15, 15)

.Size = New Size(50, 50)

.SizeMode = [Link]

.BackColor = [Link]

End With

Dim pathsToTry As String() = {

[Link] & "\[Link]",

[Link]([Link]).[Link] & "\


[Link]",

[Link]([Link]).[Link]
& "\[Link]",

"D:\POSInventory\[Link]"

Dim logoLoaded As Boolean = False

For Each filePath As String In pathsToTry

If [Link](filePath) Then

Try

Using fs As New FileStream(filePath, [Link],


[Link])

Using imgTemp As Image = [Link](fs)

[Link] = New Bitmap(imgTemp)

End Using

End Using
logoLoaded = True

Exit For

Catch ex As Exception

End Try

End If

Next

If Not logoLoaded Then

Dim bmp As New Bitmap(50, 50)

Using g As Graphics = [Link](bmp)

[Link]([Link](238, 242, 255))

[Link]("POS", New Font("Segoe UI", 11, [Link]),


[Link], New PointF(10, 15))

End Using

[Link] = bmp

End If

Dim lblSysTitle As New Label()

With lblSysTitle

.Text = "DOCTOR PLUS PHARMACY"

.Font = New Font("Segoe UI", 12, [Link])

.ForeColor = [Link]

.Location = New Point(75, 30)

.AutoSize = True

End With

' Row 1: Search Icon & TextBox

Dim lblSearchIcon As New Label() With {

.Text = "🔍",
.Font = New Font("Segoe UI", 11),

.Location = New Point(325, 25),

.Size = New Size(28, 28),

.TextAlign = [Link],

.BackColor = [Link],

.ForeColor = [Link](100, 100, 100)

txtSearch = New TextBox()

With txtSearch

.Location = New Point(353, 25)

.Width = 190

.Font = New Font("Segoe UI", 10, [Link])

End With

AddHandler [Link], AddressOf txtSearch_TextChanged

' Row 2: Category Label & ComboBox (placed directly below the search
elements)

Dim lblCatLabel As New Label() With {

.Text = "Category:",

.Font = New Font("Segoe UI", 9.5, [Link]),

.ForeColor = [Link](255, 255, 255),

.Location = New Point(325, 68),

.AutoSize = True

cmbCategory = New ComboBox()

With cmbCategory

.Location = New Point(395, 66)


.Width = 148

.Font = New Font("Segoe UI", 10)

.DropDownStyle = [Link]

End With

AddHandler [Link], AddressOf


cmbCategory_SelectedIndexChanged

lblTransNo = New Label()

With lblTransNo

.Text = "Trans No: " & currentTransactionNo

.Font = New Font("Segoe UI", 9.0, [Link])

.ForeColor = [Link]

.AutoSize = True

End With

lblUser = New Label()

With lblUser

.Text = "Cashier: " & currentLoggedInUser

.Font = New Font("Segoe UI", 8.5, [Link])

.ForeColor = [Link](255, 255, 255)

.AutoSize = True

End With

lblLiveClock = New Label()

With lblLiveClock

.Font = New Font("Segoe UI", 8.5, [Link])

.ForeColor = [Link](255, 255, 255)

.AutoSize = True

End With
' Properly anchor/organize top-right labels so they do not overlap

AddHandler [Link], Sub(s, e)

Dim rightX As Integer = [Link] -


220

[Link] = New Point(rightX, 14)

[Link] = New Point(rightX, 35)

[Link] = New Point(rightX, 55)

End Sub

[Link]({picLogo, lblSysTitle, lblSearchIcon,


txtSearch, lblCatLabel, cmbCategory, lblTransNo, lblUser, lblLiveClock})

[Link](pnlTopHeader)

[Link] = 1000

[Link]()

UpdateClockDisplay()

' 2. Right Cart Panel

pnlRightCart = New Panel()

With pnlRightCart

.Dock = [Link]

.Width = 420

.BackColor = [Link]

.Padding = New Padding(15)

End With

AddHandler [Link], Sub(s, ev)

[Link]([Link],
[Link], BorderGray, [Link])

End Sub
Dim lblCartTitle As New Label() With {.Text = "🛒 Current Order
Cart", .Font = New Font("Segoe UI", 11, [Link]), .ForeColor =
DeepIndigo, .Dock = [Link], .Height = 35}

dgvCart = New DataGridView()

With dgvCart

.Dock = [Link]

.BackgroundColor = [Link]

.BorderStyle = [Link]

.AllowUserToAddRows = False

.RowHeadersVisible = False

.SelectionMode = [Link]

.AutoSizeColumnsMode = [Link]

.[Link] = 42

.Font = New Font("Segoe UI", 9.0)

.[Link] = DeepIndigo

.[Link] = [Link]

.[Link] = New Font("Segoe UI", 9.5,


[Link])

.EnableHeadersVisualStyles = False

End With

[Link]("ProductCode", "Code")

[Link]("DrugName", "Item Name")

[Link]("UnitPrice", "Price")

[Link]("Quantity", "Qty")

[Link]("Subtotal", "Subtotal")

[Link]("ProductCode").Visible = False

[Link]("DrugName").FillWeight = 130
Dim pnlCartSummary As New Panel() With {.Dock =
[Link], .Height = 115, .BackColor = [Link](0, 0, 57)}

AddHandler [Link], Sub(s, ev)

[Link]([Link],
[Link], BorderGray, [Link])

End Sub

lblTotalItemsCount = New Label() With {.Text = "TOTAL ITEMS : 0", .Font


= New Font("Segoe UI", 9.5, [Link]), .ForeColor =
[Link], .Location = New Point(15, 15), .AutoSize = True}

lblTotalQtyCount = New Label() With {.Text = "TOTAL QTY : 0", .Font =


New Font("Segoe UI", 9.5, [Link]), .ForeColor =
[Link], .Location = New Point(15, 40), .AutoSize = True}

lblGrandTotalPrice = New Label()

With lblGrandTotalPrice

.Text = "GRAND TOTAL : ₱0.00"

.Font = New Font("Segoe UI", 12, [Link])

.ForeColor = [Link](52, 211, 153)

.Location = New Point(15, 72)

.AutoSize = True

End With

[Link]({lblTotalItemsCount,
lblTotalQtyCount, lblGrandTotalPrice})

[Link](dgvCart)

[Link](pnlCartSummary)

[Link](lblCartTitle)

' 3. Bottom Action Toolbar (Adjusted button widths to ensure "LOG OUT"
is never cut off)

Dim pnlBottomToolbar = New Panel()

With pnlBottomToolbar
.Dock = [Link]

.Height = 75

.BackColor = [Link](0, 0, 57)

.Padding = New Padding(10)

End With

AddHandler [Link], Sub(s, ev)

[Link]([Link],
[Link], BorderGray, [Link])

End Sub

Dim btnHeight As Integer = 48

Dim btnFont As New Font("Segoe UI", 8.0, [Link])

btnNewTrans = CreateToolbarButton("➕ NEW", [Link](16, 185,


129), [Link], btnHeight, btnFont)

AddHandler [Link], AddressOf btnNewTrans_Click

btnSettlePayment = CreateToolbarButton("💳 SETTLE", DeepIndigo,


[Link], btnHeight, btnFont)

AddHandler [Link], AddressOf btnSettlePayment_Click

btnPending = CreateToolbarButton("⏳ HOLD", [Link](234, 179,


8), [Link], btnHeight, btnFont)

AddHandler [Link], AddressOf btnPending_Click

btnVoid = CreateToolbarButton("❌ VOID", [Link](225, 29, 72),


[Link], btnHeight, btnFont)

AddHandler [Link], AddressOf btnVoid_Click

btnViewPending = CreateToolbarButton("📋 PEND", [Link](168,


85, 247), [Link], btnHeight, btnFont)

AddHandler [Link], AddressOf btnViewPending_Click

btnViewVoid = CreateToolbarButton(" V-VOID", [Link](244, 63,


94), [Link], btnHeight, btnFont)

AddHandler [Link], AddressOf btnViewVoid_Click


btnTransactionHistory = CreateToolbarButton("📊 HIST",
[Link](51, 65, 85), [Link], btnHeight, btnFont)

AddHandler [Link], AddressOf


btnTransactionHistory_Click

Dim btnLogOut As Button = CreateToolbarButton("🚪 LOGOUT",


[Link](71, 85, 105), [Link], btnHeight, btnFont)

AddHandler [Link], AddressOf btnLogOut_Click

Dim flpToolbarButtons As New FlowLayoutPanel()

With flpToolbarButtons

.Dock = [Link]

.FlowDirection = [Link]

.WrapContents = False

.BackColor = [Link](0, 0, 57)

.[Link]({btnNewTrans, btnSettlePayment, btnPending,


btnVoid, btnViewPending, btnViewVoid, btnTransactionHistory, btnLogOut})

End With

[Link](flpToolbarButtons)

' 4. Center Product Catalog

pnlLeftCatalog = New Panel()

With pnlLeftCatalog

.Dock = [Link]

.BackColor = ModernBgColor

End With

pnlCardWrapper = New Panel()

With pnlCardWrapper

.Dock = [Link]

.BackColor = ModernBgColor

.Padding = New Padding(12)


End With

flpProducts = New FlowLayoutPanel()

With flpProducts

.Dock = [Link]

.AutoScroll = True

.FlowDirection = [Link]

.WrapContents = True

.BackColor = ModernBgColor

End With

[Link](flpProducts)

[Link](pnlCardWrapper)

' Add controls in proper layout order

[Link](pnlTopHeader)

[Link](pnlBottomToolbar)

[Link](pnlRightCart)

[Link](pnlLeftCatalog)

End Sub

Private Function CreateToolbarButton(text As String, bgColor As Color,


fgColor As Color, heightVal As Integer, btnFont As Font) As Button

Dim btn As New Button()

With btn

.Text = text

.BackColor = bgColor

.ForeColor = fgColor

.FlatStyle = [Link]

.[Link] = 0

.Font = btnFont
.Height = heightVal

.Width = 98

.Margin = New Padding(4, 0, 4, 0)

.Cursor = [Link]

End With

Return btn

End Function

Private Sub btnLogOut_Click(sender As Object, e As EventArgs)

Dim logoutForm As New logout()

[Link](Me)

End Sub

Private Sub LoadCategories()

[Link]()

[Link]("All Categories")

Dim query As String = "SELECT DISTINCT CategoryName FROM


[Link] WHERE (IsArchived = 0 OR IsArchived IS NULL) AND
CategoryName IS NOT NULL"

Using conn As SqlConnection = [Link]()

Try

[Link]()

Using cmd As New SqlCommand(query, conn)

Using reader As SqlDataReader = [Link]()

While [Link]()

[Link](reader("CategoryName").ToString())

End While

End Using

End Using
Catch ex As Exception

End Try

End Using

If [Link] > 0 Then [Link] = 0

End Sub

Private Sub LoadProductCatalog(searchKeyword As String, categoryFilter


As String)

[Link]()

[Link]()

Dim query As String = "SELECT ProductCode, DrugName,


CategoryName, UnitPrice, Quantity, ProductImage FROM [Link]
WHERE (IsArchived = 0 OR IsArchived IS NULL)"

If Not [Link](searchKeyword) Then

query &= " AND (DrugName LIKE @search OR ProductCode LIKE


@search)"

End If

If categoryFilter <> "All Categories" Then

query &= " AND CategoryName = @category"

End If

Using conn As SqlConnection = [Link]()

Try

[Link]()

Using cmd As New SqlCommand(query, conn)

If Not [Link](searchKeyword) Then

[Link]("@search", "%" &


searchKeyword & "%")

End If

If categoryFilter <> "All Categories" Then


[Link]("@category", categoryFilter)

End If

Using reader As SqlDataReader = [Link]()

While [Link]()

Dim pCode As String = reader("ProductCode").ToString()

Dim dName As String = reader("DrugName").ToString()

Dim cName As String = reader("CategoryName").ToString()

Dim uPrice As Decimal = If(IsDBNull(reader("UnitPrice")), 0,


[Link](reader("UnitPrice")))

Dim qty As Integer = If(IsDBNull(reader("Quantity")), 0,


Convert.ToInt32(reader("Quantity")))

Dim imgPath As String =


If(IsDBNull(reader("ProductImage")), "", reader("ProductImage").ToString())

Dim card As New Panel()

With card

.Width = 158

.Height = 220

.BackColor = CardBgColor

.Margin = New Padding(10)

.Cursor = [Link]

.Tag = pCode

End With

AddHandler [Link], Sub(s, ev)

Dim g As Graphics = [Link]

[Link] =
[Link]

Dim rect As New Rectangle(3, 3,


[Link] - 8, [Link] - 8)
Dim radius As Integer = 12

Using pathShadow As
[Link] = GetRoundedRectPath(New Rectangle(4, 4,
[Link] - 7, [Link] - 7), radius)

Using shadowBrush As New


SolidBrush([Link](50, 75, 0, 130))

[Link](shadowBrush, pathShadow)

End Using

End Using

Using pathCard As
[Link] = GetRoundedRectPath(rect, radius)

[Link]([Link], pathCard)

Using penBorder As New


Pen([Link](147, 112, 219), 1.2F)

[Link](penBorder, pathCard)

End Using

End Using

End Sub

AddHandler [Link], Sub(s, e)

[Link] = [Link](241,
245, 249)

[Link]()

End Sub

AddHandler [Link], Sub(s, e)

[Link] = CardBgColor

[Link]()

End Sub

Dim picBox As New PictureBox()

With picBox
.Width = 142

.Height = 95

.Location = New Point(8, 8)

.SizeMode = [Link]

.BackColor = [Link](241, 245, 249)

End With

If [Link](imgPath) Then

[Link] = [Link](imgPath)

Else

Dim bmp As New Bitmap(142, 95)

Using g As Graphics = [Link](bmp)

[Link]([Link](241, 245, 249))

[Link]("💊 No Image", New Font("Segoe UI", 8.5,


[Link]), [Link], New PointF(32, 38))

End Using

[Link] = bmp

End If

Dim lblName As New Label()

With lblName

.Text = dName

.Font = New Font("Segoe UI", 9, [Link])

.ForeColor = [Link](30, 41, 59)

.Location = New Point(8, 110)

.Width = 142

.Height = 35

.UseMnemonic = False

End With
Dim lblPriceQty As New Label()

With lblPriceQty

.Text = "₱" & [Link]("N2") & " | Q: " &


[Link]()

.Font = New Font("Segoe UI", 8, [Link])

.Location = New Point(8, 150)

.Width = 142

.Height = 18

If qty = 0 Then

.ForeColor = [Link](225, 29, 72)

Else

.ForeColor = [Link](16, 185, 129)

End If

End With

Dim btnMinus As New Button()

With btnMinus

.Text = "-"

.Font = New Font("Segoe UI", 9, [Link])

.BackColor = [Link](226, 232, 240)

.ForeColor = [Link](51, 65, 85)

.FlatStyle = [Link]

.[Link] = 0

.Size = New Size(42, 28)

.Location = New Point(8, 178)

.Cursor = [Link]

End With

Dim btnPlus As New Button()


With btnPlus

.Text = "+"

.Font = New Font("Segoe UI", 9, [Link])

.BackColor = DeepIndigo

.ForeColor = [Link]

.FlatStyle = [Link]

.[Link] = 0

.Size = New Size(42, 28)

.Location = New Point(108, 178)

.Cursor = [Link]

End With

Dim lblActionHint As New Label()

With lblActionHint

.Text = "QTY"

.Font = New Font("Segoe UI", 7.5, [Link])

.ForeColor = [Link](100, 116, 139)

.TextAlign = [Link]

.Location = New Point(52, 182)

.Width = 54

.Height = 20

End With

AddHandler [Link], Sub(s, e) AddToCart(pCode,


dName, uPrice, qty)

AddHandler [Link], Sub(s, e)


RemoveOneFromCart(pCode)

AddHandler [Link], Sub(s, e) AddToCart(pCode, dName,


uPrice, qty)
AddHandler [Link], Sub(s, e) AddToCart(pCode,
dName, uPrice, qty)

AddHandler [Link], Sub(s, e) AddToCart(pCode,


dName, uPrice, qty)

[Link]({picBox, lblName, lblPriceQty,


btnMinus, btnPlus, lblActionHint})

[Link](card)

End While

End Using

End Using

Catch ex As Exception

[Link]("Error loading catalog: " & [Link],


"Database Error", [Link], [Link])

Finally

[Link]()

End Try

End Using

End Sub

Private Function GetRoundedRectPath(rect As Rectangle, radius As Integer)


As [Link]

Dim path As New [Link]()

Dim diameter As Integer = radius * 2

[Link](rect.X, rect.Y, diameter, diameter, 180, 90)

[Link]([Link] - diameter, rect.Y, diameter, diameter, 270, 90)

[Link]([Link] - diameter, [Link] - diameter, diameter,


diameter, 0, 90)

[Link](rect.X, [Link] - diameter, diameter, diameter, 90, 90)

[Link]()

Return path
End Function

Private Sub AddToCart(productCode As String, drugName As String,


unitPrice As Decimal, availableQty As Integer)

If availableQty <= 0 Then

[Link]("This item is currently Out of Stock!", "Stock


Alert", [Link], [Link])

Return

End If

Dim itemFound As Boolean = False

For Each row As DataGridViewRow In [Link]

If [Link]("ProductCode").[Link]() = productCode Then

Dim currentQty As Integer =


Convert.ToInt32([Link]("Quantity").Value)

If currentQty + 1 > availableQty Then

[Link]("Cannot add more than available stock limit


(" & availableQty & ").", "Inventory Limit", [Link],
[Link])

Return

End If

[Link]("Quantity").Value = currentQty + 1

[Link]("Subtotal").Value = "₱" & ((currentQty + 1) *


unitPrice).ToString("N2")

itemFound = True

Exit For

End If

Next

If Not itemFound Then

[Link](productCode, drugName, "₱" &


[Link]("N2"), 1, "₱" & [Link]("N2"))
End If

CalculateCartTotals()

End Sub

Private Sub RemoveOneFromCart(productCode As String)

For Each row As DataGridViewRow In [Link]

If [Link]("ProductCode").[Link]() = productCode Then

Dim currentQty As Integer =


Convert.ToInt32([Link]("Quantity").Value)

Dim unitPrice As Decimal =


[Link]([Link]("Subtotal").[Link]().Replace("₱",
"").Trim()) / currentQty

If currentQty > 1 Then

[Link]("Quantity").Value = currentQty - 1

[Link]("Subtotal").Value = "₱" & ((currentQty - 1) *


unitPrice).ToString("N2")

Else

[Link](row)

End If

CalculateCartTotals()

Exit For

End If

Next

End Sub

Private Sub CalculateCartTotals()

Dim grandTotal As Decimal = 0

Dim totalItemsDistinct As Integer = [Link]

Dim totalQtyCount As Integer = 0

For Each row As DataGridViewRow In [Link]


Dim subTotalStr As String =
[Link]("Subtotal").[Link]().Replace("₱", "").Trim()

grandTotal += [Link](subTotalStr)

totalQtyCount += Convert.ToInt32([Link]("Quantity").Value)

Next

[Link] = "TOTAL ITEMS : " & totalItemsDistinct

[Link] = "TOTAL QTY : " & totalQtyCount

[Link] = "GRAND TOTAL : ₱" &


[Link]("N2")

End Sub

Private Sub txtSearch_TextChanged(sender As Object, e As EventArgs)

LoadProductCatalog([Link](), [Link])

End Sub

Private Sub cmbCategory_SelectedIndexChanged(sender As Object, e As


EventArgs)

If [Link] Is Nothing Then Return

LoadProductCatalog([Link](),
[Link]())

End Sub

Private Sub btnNewTrans_Click(sender As Object, e As EventArgs)

[Link]()

CalculateCartTotals()

GenerateNewTransactionNumber()

[Link] = "Trans No: " & currentTransactionNo

End Sub

Private Sub btnSettlePayment_Click(sender As Object, e As EventArgs)

If [Link] = 0 Then
[Link]("There are no items in the cart to settle.", "Empty
Cart", [Link], [Link])

Return

End If

Dim totalItems As Integer = 0

Dim totalQty As Integer = 0

Dim grandTotal As Decimal = 0

Dim cartTable As New DataTable()

[Link]("Item Name", GetType(String))

[Link]("Price", GetType(Decimal))

[Link]("Qty", GetType(Integer))

[Link]("Subtotal", GetType(Decimal))

For Each row As DataGridViewRow In [Link]

If Not [Link] Then

Dim itemName As String = If([Link]("DrugName").Value IsNot


Nothing, [Link]("DrugName").[Link](), "")

Dim price As Decimal = 0

Dim qty As Integer = 0

Dim subtotal As Decimal = 0

Dim rawPrice As String = If([Link]("UnitPrice").Value IsNot


Nothing, [Link]("UnitPrice").[Link]().Replace("₱", "").Trim(), "0")

[Link](rawPrice, price)

[Link](If([Link]("Quantity").Value IsNot Nothing,


[Link]("Quantity").[Link](), "0"), qty)

Dim rawSubtotal As String = If([Link]("Subtotal").Value IsNot


Nothing, [Link]("Subtotal").[Link]().Replace("₱", "").Trim(), "0")

[Link](rawSubtotal, subtotal)

If qty > 0 AndAlso Not [Link](itemName) Then


[Link](itemName, price, qty, subtotal)

totalItems += 1

totalQty += qty

End If

End If

Next

Dim rawTotalText As String = [Link]

Dim cleanedTotalText As String = New


String([Link](Function(c) [Link](c) OrElse c =
"."c).ToArray())

[Link](cleanedTotalText, grandTotal)

Dim transNo As String = [Link]

Dim cashierName As String = [Link]

If [Link] > 0 Then

Using settleForm As New SettlePaymentForm(grandTotal, totalItems,


totalQty, cartTable, transNo, cashierName)

If [Link]() = [Link] Then

[Link]()

CalculateCartTotals()

LoadProductCatalog("", "All Categories")

GenerateNewTransactionNumber()

End If

End Using

End If

End Sub

Private Sub btnPending_Click(sender As Object, e As EventArgs)

If [Link] = 0 Then
[Link]("There are no items in the cart to hold as
pending.", "Empty Cart", [Link], [Link])

Return

End If

Dim transNo As String = currentTransactionNo

Dim cashierName As String = currentLoggedInUser

Dim grandTotal As Decimal = 0

Dim rawTotalText As String = [Link]

Dim cleanedTotalText As String = New


String([Link](Function(c) [Link](c) OrElse c =
"."c).ToArray())

[Link](cleanedTotalText, grandTotal)

Dim totalItemsCount As Integer = [Link]

Dim totalQtyCount As Integer = 0

For Each row As DataGridViewRow In [Link]

totalQtyCount += Convert.ToInt32([Link]("Quantity").Value)

Next

Using conn As SqlConnection = [Link]()

Try

[Link]()

Using tran As SqlTransaction = [Link]()

Using cmd As New SqlCommand("INSERT INTO


PendingTransactions (TransactionNo, CashierName, TotalAmount, TotalItems,
TotalQty, DateSaved) OUTPUT [Link] VALUES (@TransNo,
@Cashier, @Total, @Items, @Qty, GETDATE())", conn, tran)

[Link]("@TransNo", transNo)

[Link]("@Cashier", cashierName)

[Link]("@Total", grandTotal)

[Link]("@Items", totalItemsCount)
[Link]("@Qty", totalQtyCount)

Dim pendingID As Integer =


Convert.ToInt32([Link]())

For Each row As DataGridViewRow In [Link]

If Not [Link] Then

Dim pCode As String =


[Link]("ProductCode").[Link]()

Dim dName As String =


[Link]("DrugName").[Link]()

Dim uPrice As Decimal =


[Link]([Link]("UnitPrice").[Link]().Replace("₱",
"").Trim())

Dim qty As Integer =


Convert.ToInt32([Link]("Quantity").Value)

Dim subtotal As Decimal =


[Link]([Link]("Subtotal").[Link]().Replace("₱",
"").Trim())

Using itemCmd As New SqlCommand("INSERT INTO


PendingTransactionItems (PendingID, ProductCode, DrugName, UnitPrice,
Quantity, Subtotal) VALUES (@PID, @Code, @Name, @Price, @Qty, @Sub)",
conn, tran)

[Link]("@PID",
pendingID)

[Link]("@Code", pCode)

[Link]("@Name",
dName)

[Link]("@Price", uPrice)

[Link]("@Qty", qty)

[Link]("@Sub", subtotal)

[Link]()

End Using
End If

Next

End Using

[Link]()

End Using

[Link]()

CalculateCartTotals()

LoadProductCatalog("", "All Categories")

GenerateNewTransactionNumber()

Catch ex As Exception

End Try

End Using

End Sub

Private Sub btnVoid_Click(sender As Object, e As EventArgs)

If [Link] = 0 Then

Return

End If

Dim passwordInput As String = ""

Dim voidReasonInput As String = ""

Using authForm As New VoidAuthForm(currentLoggedInUser)

If [Link]() <> [Link] Then Return

passwordInput = [Link]

voidReasonInput = [Link]

End Using

If Not VerifyUserPassword(currentLoggedInUser, passwordInput) Then

Return

End If
Dim generatedVoidNo As String = GenerateVoidTransactionNumber()

Dim grandTotal As Decimal = 0

Dim rawTotalText As String = [Link]

Dim cleanedTotalText As String = New


String([Link](Function(c) [Link](c) OrElse c =
"."c).ToArray())

[Link](cleanedTotalText, grandTotal)

Dim totalItemsCount As Integer = [Link]

Dim totalQtyCount As Integer = 0

For Each row As DataGridViewRow In [Link]

totalQtyCount += Convert.ToInt32([Link]("Quantity").Value)

Next

Using conn As SqlConnection = [Link]()

Try

[Link]()

Using tran As SqlTransaction = [Link]()

Dim insertVoidQuery As String = "INSERT INTO


VoidedTransactions (VoidTransactionNo, TransactionNo, CashierName,
AuthorizedBy, TotalAmount, TotalItems, TotalQty, VoidReason, DateVoided)
OUTPUT [Link] VALUES (@VoidNo, @TransNo, @Cashier, @AuthBy,
@Total, @Items, @Qty, @Reason, GETDATE())"

Dim originalTransNo As String = [Link]("Trans


No:", "").Trim()

Using cmd As New SqlCommand(insertVoidQuery, conn, tran)

[Link]("@VoidNo", generatedVoidNo)

[Link]("@TransNo", originalTransNo)

[Link]("@Cashier",
currentLoggedInUser)

[Link]("@AuthBy",
currentLoggedInUser)
[Link]("@Total", grandTotal)

[Link]("@Items", totalItemsCount)

[Link]("@Qty", totalQtyCount)

[Link]("@Reason", voidReasonInput)

Dim voidID As Integer =


Convert.ToInt32([Link]())

For Each row As DataGridViewRow In [Link]

If Not [Link] Then

Dim pCode As String =


[Link]("ProductCode").[Link]()

Dim dName As String =


[Link]("DrugName").[Link]()

Dim uPrice As Decimal =


[Link]([Link]("UnitPrice").[Link]().Replace("₱",
"").Trim())

Dim qty As Integer =


Convert.ToInt32([Link]("Quantity").Value)

Dim subtotal As Decimal =


[Link]([Link]("Subtotal").[Link]().Replace("₱",
"").Trim())

Dim itemQuery As String = "INSERT INTO


VoidedTransactionItems (VoidID, ProductCode, DrugName, UnitPrice,
Quantity, Subtotal) VALUES (@VID, @Code, @Name, @Price, @Qty, @Sub)"

Using itemCmd As New SqlCommand(itemQuery, conn,


tran)

[Link]("@VID", voidID)

[Link]("@Code", pCode)

[Link]("@Name",
dName)

[Link]("@Price", uPrice)

[Link]("@Qty", qty)
[Link]("@Sub", subtotal)

[Link]()

End Using

End If

Next

End Using

[Link]()

End Using

[Link]()

CalculateCartTotals()

LoadProductCatalog("", "All Categories")

GenerateNewTransactionNumber()

Catch ex As Exception

End Try

End Using

End Sub

Private Function VerifyUserPassword(username As String, password As


String) As Boolean

Using conn As SqlConnection = [Link]()

Try

[Link]()

Dim query As String = "SELECT COUNT(1) FROM [Link] WHERE


Username = @User AND Password = @Pass"

Using cmd As New SqlCommand(query, conn)

[Link]("@User", username)

[Link]("@Pass", password)

Dim count As Integer = Convert.ToInt32([Link]())


Return count > 0

End Using

Catch ex As Exception

Return True

End Try

End Using

End Function

Private Sub btnViewPending_Click(sender As Object, e As EventArgs)

Using pendingForm As New ViewPendingForm()

If [Link]() = [Link] Then

If [Link] IsNot Nothing AndAlso


[Link] > 0 Then

If [Link] > 0 Then

[Link]()

End If

For Each dr As DataRow In [Link]

[Link](

dr("ProductCode"),

dr("DrugName"),

"₱" & [Link](dr("UnitPrice")).ToString("N2"),

dr("Quantity"),

"₱" & [Link](dr("Subtotal")).ToString("N2")

Next

currentTransactionNo = [Link]

[Link] = currentTransactionNo

CalculateCartTotals()
End If

End If

End Using

End Sub

Private Function GenerateVoidTransactionNumber() As String

Dim newVoidNo As String = "VOID-000001"

Using conn As SqlConnection = [Link]()

Try

[Link]()

Dim query As String = "SELECT TOP 1 VoidTransactionNo FROM


[Link] ORDER BY VoidID DESC"

Using cmd As New SqlCommand(query, conn)

Dim result = [Link]()

If result IsNot Nothing AndAlso result IsNot [Link] Then

Dim lastNo As String = [Link]()

Dim parts() As String = [Link]("-"c)

If [Link] > 1 AndAlso IsNumeric(parts([Link] - 1))


Then

Dim nextNum As Integer =


Convert.ToInt32(parts([Link] - 1)) + 1

newVoidNo = "VOID-" & [Link]("D6")

End If

End If

End Using

Catch EX As Exception

newVoidNo = "VOID-" &


[Link]("yyyyMMddHHmmss")

End Try
End Using

Return newVoidNo

End Function

Private Sub btnViewVoid_Click(sender As Object, e As EventArgs)

Using voidForm As New ViewVoidForm()

[Link]()

End Using

End Sub

Private Sub btnTransactionHistory_Click(sender As Object, e As EventArgs)

Using historyForm As New ViewHistoryForm()

[Link]()

End Using

End Sub

End Class

You might also like