Puberty flex | First birthday flex | Death flex | Memorial flex | Madurai flex | Tvk | Admk | Dmk | Pmk | Vck

Vb.net Billing Software Source Code | FAST |

Once you have the base VB.NET billing software source code, consider these enhancements:


-- Products Table
CREATE TABLE tbl_Products (
    ProductID INT PRIMARY KEY IDENTITY(1,1),
    ProductName NVARCHAR(100) NOT NULL,
    HSNCode NVARCHAR(20),
    PurchasePrice DECIMAL(18,2),
    SellingPrice DECIMAL(18,2),
    GST_Percent INT, -- e.g., 5, 12, 18, 28
    StockQuantity INT DEFAULT 0
);

-- Customers Table CREATE TABLE tbl_Customers ( CustomerID INT PRIMARY KEY IDENTITY(1,1), CustomerName NVARCHAR(100), Phone NVARCHAR(15), GST_No NVARCHAR(15) -- For B2B invoices );

-- Invoice Master Table (One invoice per record) CREATE TABLE tbl_Invoice_Master ( InvoiceNo INT PRIMARY KEY IDENTITY(1,1), InvoiceDate DATETIME DEFAULT GETDATE(), CustomerID INT FOREIGN KEY REFERENCES tbl_Customers(CustomerID), SubTotal DECIMAL(18,2), TaxAmount DECIMAL(18,2), GrandTotal DECIMAL(18,2) ); vb.net billing software source code

-- Invoice Details Table (Multiple rows per invoice) CREATE TABLE tbl_Invoice_Details ( DetailID INT PRIMARY KEY IDENTITY(1,1), InvoiceNo INT FOREIGN KEY REFERENCES tbl_Invoice_Master(InvoiceNo), ProductID INT FOREIGN KEY REFERENCES tbl_Products(ProductID), Quantity INT, Rate DECIMAL(18,2), Total DECIMAL(18,2) );

Imports System.Data.SqlClient

Public Class frmBilling Private dtCart As New DataTable() Private currentInvoiceNumber As String = ""

Private Sub frmBilling_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    InitializeCartTable()
    GenerateInvoiceNumber()
    LoadProducts()
    LoadCustomers()
End Sub
Private Sub InitializeCartTable()
    dtCart.Columns.Add("ProductID", GetType(Integer))
    dtCart.Columns.Add("ProductCode", GetType(String))
    dtCart.Columns.Add("ProductName", GetType(String))
    dtCart.Columns.Add("Quantity", GetType(Integer))
    dtCart.Columns.Add("UnitPrice", GetType(Decimal))
    dtCart.Columns.Add("GST", GetType(Decimal))
    dtCart.Columns.Add("Total", GetType(Decimal))
    dgvCart.DataSource = dtCart
    FormatDataGridView()
End Sub
Private Sub FormatDataGridView()
    dgvCart.Columns("ProductID").Visible = False
    dgvCart.Columns("ProductCode").HeaderText = "Product Code"
    dgvCart.Columns("ProductName").HeaderText = "Product Name"
    dgvCart.Columns("Quantity").HeaderText = "Qty"
    dgvCart.Columns("UnitPrice").HeaderText = "Unit Price"
    dgvCart.Columns("GST").HeaderText = "GST %"
    dgvCart.Columns("Total").HeaderText = "Total"
    dgvCart.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill
End Sub
Private Sub GenerateInvoiceNumber()
    currentInvoiceNumber = "INV-" & DateTime.Now.ToString("yyyyMMdd") & "-" & DateTime.Now.ToString("HHmmss")
    txtInvoiceNo.Text = currentInvoiceNumber
End Sub
Private Sub LoadProducts()
    Try
        Dim dt As DataTable = Product.GetAllProducts()
        cmbProductName.DataSource = dt
        cmbProductName.DisplayMember = "ProductName"
        cmbProductName.ValueMember = "ProductID"
        cmbProductName.SelectedIndex = -1
    Catch ex As Exception
        MessageBox.Show("Error loading products: " & ex.Message)
    End Try
End Sub
Private Sub LoadCustomers()
    Try
        Dim query As String = "SELECT CustomerID, CustomerName FROM Customers"
        DBConnection.OpenConnection()
        Dim adapter As New SqlDataAdapter(query, DBConnection.conn)
        Dim dt As New DataTable()
        adapter.Fill(dt)
        cmbCustomer.DataSource = dt
        cmbCustomer.DisplayMember = "CustomerName"
        cmbCustomer.ValueMember = "CustomerID"
        DBConnection.CloseConnection()
    Catch ex As Exception
        MessageBox.Show("Error loading customers: " & ex.Message)
    End Try
End Sub
Private Sub cmbProductName_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmbProductName.SelectedIndexChanged
    If cmbProductName.SelectedValue IsNot Nothing Then
        Try
            Dim productID As Integer = Convert.ToInt32(cmbProductName.SelectedValue)
            Dim query As String = "SELECT ProductCode, UnitPrice, GSTPercentage FROM Products WHERE ProductID = @ProductID"
            DBConnection.OpenConnection()
            Using cmd As New SqlCommand(query, DBConnection.conn)
                cmd.Parameters.AddWithValue("@ProductID", productID)
                Using reader As SqlDataReader = cmd.ExecuteReader()
                    If reader.Read() Then
                        txtProductCode.Text = reader("ProductCode").ToString()
                        txtPrice.Text = reader("UnitPrice").ToString()
                        txtGST.Text = reader("GSTPercentage").ToString()
                        txtQuantity.Text = "1"
                        CalculateTotal()
                    End If
                End Using
            End Using
            DBConnection.CloseConnection()
        Catch ex As Exception
            MessageBox.Show("Error: " & ex.Message)
        End Try
    End If
End Sub
Private Sub CalculateTotal()
    If txtQuantity.Text <> "" And txtPrice.Text <> "" Then
        Dim quantity As Integer = Integer.Parse(txtQuantity.Text)
        Dim price As Decimal = Decimal.Parse(txtPrice.Text)
        Dim gst As Decimal = Decimal.Parse(txtGST.Text)
        Dim subtotal As Decimal = quantity * price
        Dim gstAmount As Decimal = subtotal * (gst / 100)
        Dim total As Decimal = subtotal + gstAmount
        txtSubtotal.Text = subtotal.ToString("N2")
        txtGSTAmount.Text = gstAmount.ToString("N2")
        txtTotal.Text = total.ToString("N2")
    End If
End Sub
Private Sub txtQuantity_TextChanged(sender As Object, e As EventArgs) Handles txtQuantity.TextChanged
    CalculateTotal()
End Sub
Private Sub btnAddToCart_Click(sender As Object, e As EventArgs) Handles btnAddToCart.Click
    If cmbProductName.SelectedValue Is Nothing Then
        MessageBox.Show("Please select a product")
        Return
    End If
Dim productID As Integer = Convert.ToInt32(cmbProductName.SelectedValue)
    Dim productCode As String = txtProductCode.Text
    Dim productName As String = cmbProductName.Text
    Dim quantity As Integer = Integer.Parse(txtQuantity.Text)
    Dim unitPrice As Decimal = Decimal.Parse(txtPrice.Text)
    Dim gst As Decimal = Decimal.Parse(txtGST.Text)
    Dim total As Decimal = Decimal.Parse(txtTotal.Text)
' Check if product already in cart
    Dim existingRow As DataRow() = dtCart.Select("ProductID = " & productID)
    If existingRow.Length > 0 Then
        existingRow(0)("Quantity") = CInt(existingRow(0)("Quantity")) + quantity
        existingRow(0)("Total") = CDec(existingRow(0)("Quantity")) * unitPrice
    Else
        dtCart.Rows.Add(productID, productCode, productName, quantity, unitPrice, gst, total)
    End If
UpdateGrandTotal()
    ClearProductFields()
End Sub
Private Sub UpdateGrandTotal()
    Dim grandTotal As Decimal = 0
    For Each row As DataRow In dtCart.Rows
        grandTotal += CDec(row("Total"))
    Next
    lblGrandTotal.Text = "Grand Total: ₹" & grandTotal.ToString("N2")
End Sub
Private Sub ClearProductFields()
    cmbProductName.SelectedIndex = -1
    txtProductCode.Clear()
    txtPrice.Clear()
    txtGST.Clear()
    txtQuantity.Clear()
    txtSubtotal.Clear()
    txtGSTAmount.Clear()
    txtTotal.Clear()
    txtQuantity.Text = "1"
End Sub
Private Sub btnRemoveFromCart_Click(sender As Object, e As EventArgs) Handles btnRemoveFromCart.Click
    If dgvCart.CurrentRow IsNot Nothing Then
        dtCart.Rows.RemoveAt(dgvCart.CurrentRow.Index)
        UpdateGrandTotal()
    End If
End Sub
Private Sub btnSaveInvoice_Click(sender As Object, e As EventArgs) Handles btnSaveInvoice.Click
    If dtCart.Rows.Count = 0 Then
        MessageBox.Show("Cart is empty!")
        Return
    End If
If cmbCustomer.SelectedValue Is Nothing Then
        MessageBox.Show("Please select a customer")
        Return
    End If
Try
        DBConnection.OpenConnection()
        Dim transaction As SqlTransaction = DBConnection.conn.BeginTransaction()
Try
            ' Calculate totals
            Dim subtotal As Decimal = 0
            Dim totalGST As Decimal = 0
            For Each row As DataRow In dtCart.Rows
                subtotal += CDec(row("Total"))
            Next
Dim totalAmount As Decimal = subtotal
' Insert Invoice
            Dim invoiceQuery As String = "INSERT INTO Invoices (InvoiceNumber, CustomerID, InvoiceDate, SubTotal, GSTAmount, TotalAmount, PaymentMethod, Status) VALUES (@InvoiceNo, @CustomerID, @Date, @SubTotal, @GST, @Total, @PaymentMethod, 'Completed') SELECT SCOPE_IDENTITY()"
Using cmd As New SqlCommand(invoiceQuery, DBConnection.conn, transaction)
                cmd.Parameters.AddWithValue("@InvoiceNo", txtInvoiceNo.Text)
                cmd.Parameters.AddWithValue("@CustomerID", Convert.ToInt32(cmbCustomer.SelectedValue))
                cmd.Parameters.AddWithValue("@Date", DateTime.Now)
                cmd.Parameters.AddWithValue("@SubTotal", subtotal)
                cmd.Parameters.AddWithValue("@GST", totalGST)
                cmd.Parameters.AddWithValue("@Total", totalAmount)
                cmd.Parameters.AddWithValue("@PaymentMethod", cmbPaymentMethod.Text)
Dim invoiceID As Integer = Convert.ToInt32(cmd.ExecuteScalar())
' Insert Invoice Items
                For Each row As DataRow In dtCart.Rows
                    Dim itemQuery As String = "INSERT INTO InvoiceItems (InvoiceID, ProductID, Quantity, UnitPrice, TotalPrice, GSTAmount) VALUES (@InvoiceID, @ProductID, @Quantity, @UnitPrice, @TotalPrice, @GSTAmount)"
                    Using itemCmd As New SqlCommand(itemQuery, DBConnection.conn, transaction)
                        itemCmd.Parameters.AddWithValue("@InvoiceID", invoiceID)
                        itemCmd.Parameters.AddWithValue("@ProductID", row("ProductID"))
                        itemCmd.Parameters.AddWithValue("@Quantity", row("Quantity"))
                        itemCmd.Parameters.AddWithValue("@UnitPrice", row("UnitPrice"))
                        itemCmd.Parameters.AddWithValue("@TotalPrice", row("Total"))
                        itemCmd.Parameters.AddWithValue("@GSTAmount", 0)
                        itemCmd.ExecuteNonQuery()
                    End Using
                Next
            End Using
transaction.Commit()
            MessageBox.Show("Invoice saved successfully! Invoice No: " & txtInvoiceNo.Text)
' Print receipt
            PrintReceipt()
' Reset form
            ResetForm()
Catch ex As Exception
            transaction.Rollback()
            MessageBox.Show("Error saving invoice: " & ex.Message)
        End Try
Catch ex As Exception
        MessageBox.Show("Database error: " & ex.Message)
    Finally
        DBConnection.CloseConnection()
    End Try
End Sub
Private Sub PrintReceipt()
    ' Simple print preview
    Dim printDialog As New PrintDialog()
    Dim printDocument As New Printing.PrintDocument()
AddHandler printDocument.PrintPage, AddressOf PrintDocument_PrintPage
printDialog.Document = printDocument
    If printDialog.ShowDialog() = DialogResult.OK Then
        printDocument.Print()
    End If
End Sub
Private Sub PrintDocument_PrintPage(sender As Object, e As Printing.PrintPageEventArgs)
    Dim font As New Font("Arial", 10)
    Dim titleFont As New Font("Arial", 14, FontStyle.Bold)
    Dim yPos As Single = 50
    Dim leftMargin As Single = 50
    Dim xPos As Single = leftMargin
' Print Header
    e.Graphics.DrawString("BILLING SYSTEM", titleFont, Brushes.Black, xPos, yPos)
    yPos += 30
    e.Graphics.DrawString("Invoice No: " & txtInvoiceNo.Text, font, Brushes.Black, xPos, yPos)
    yPos += 20
    e.Graphics.DrawString("Date: " & DateTime.Now.ToString(), font, Brushes.Black, xPos, yPos)
    yPos += 20
    e.Graphics.DrawString("Customer: " & cmbCustomer.Text, font, Brushes.Black, xPos, yPos)
    yPos += 30
' Print Column Headers
    e.Graphics.DrawString("Product", font, Brushes.Black, xPos, yPos)
    e.Graphics.DrawString("Qty", font, Brushes.Black, xPos + 150, yPos)
    e.Graphics.DrawString("Price", font, Brushes.Black, xPos + 250, yPos)
    e.Graphics.DrawString("Total", font, Brushes.Black, xPos + 350, yPos)
    yPos += 20
    e.Graphics.DrawLine(Pens.Black, leftMargin, yPos, 500, yPos)
    yPos += 10
' Print Items
    For Each row As DataRow In dtCart.Rows
        e.Graphics.DrawString(row("ProductName").ToString(), font, Brushes.Black, xPos, yPos)
        e.Graphics.DrawString(row("Quantity").ToString(), font, Brushes.Black, xPos + 150, yPos)
        e.Graphics.DrawString(CDec(row("UnitPrice")).ToString("N2"), font, Brushes.Black, xPos + 250, yPos)
        e.Graphics.DrawString(CDec(row("Total")).ToString("N2"), font, Brushes.Black, xPos + 350, yPos)
        yPos += 20
    Next
yPos += 10
    e.Graphics.DrawLine(Pens.Black, leftMargin, yPos, 500, yPos)
    yPos += 10
    e.Graphics.DrawString("Grand Total: " & lblGrandTotal.Text, titleFont, Brushes.Black, xPos, yPos)
End Sub
Private Sub ResetForm()
    dtCart.Clear()
    GenerateInvoiceNumber()
    UpdateGrandTotal()
    ClearProductFields()
    cmbCustomer.SelectedIndex = -1
    cmbPaymentMethod.SelectedIndex = -1
End Sub

End Class

The reviewed billing software provides core functionality for invoice generation, customer management, and basic reporting. While the application fulfills basic business requirements, the source code reveals significant architectural debt. The project relies heavily on legacy patterns (likely ported from VB6) and lacks modern development standards such as Dependency Injection and Unit Testing. Immediate refactoring is recommended to ensure long-term maintainability. Once you have the base VB


A professional billing software source code package should include at least these modules:

| Module | Description | |--------|-------------| | Product Master | Add, edit, delete, search products (Code, Name, Unit, Price, GST%, HSN code). | | Customer/Party Master | Manage customer details, credit limits, and GSTIN numbers. | | Invoice/Bill Entry | Create new bills, add line items, auto-calculate totals, taxes, discounts. | | Print Invoice | Generate printable or PDF invoices with company logo and terms. | | Stock Management | Track inventory quantities, low stock alerts, and stock valuation. | | GST / Tax Reports | Show tax breakup (CGST, SGST, IGST) and generate GSTR-1 like summaries. | | Sales Report | View daily, monthly, or custom date range sales. | | Backup & Restore | Backup SQL Server or MS Access database with one click. | -- Products Table CREATE TABLE tbl_Products ( ProductID