Vb.net Billing Software Source Code -

End Sub

Usually utilizes System.Drawing.Printing or third-party libraries to render the invoice layout. 3. Sample VB.NET Billing Code Snippets

Provides complete, downloadable open-source billing applications. Conclusion

You might be thinking, “Why not start from a blank screen?” vb.net billing software source code

CREATE DATABASE BillingDB; GO USE BillingDB; GO -- 1. Inventory/Products Table CREATE TABLE Products ( ProductID INT IDENTITY(1,1) PRIMARY KEY, ProductCode VARCHAR(50) UNIQUE NOT NULL, ProductName NVARCHAR(150) NOT NULL, UnitPrice DECIMAL(18, 2) NOT NULL DEFAULT 0.00, StockQuantity INT NOT NULL DEFAULT 0 ); -- 2. Customers Table CREATE TABLE Customers ( CustomerID INT IDENTITY(1,1) PRIMARY KEY, CustomerName NVARCHAR(100) NOT NULL, ContactNumber VARCHAR(20) NULL, Email VARCHAR(100) NULL ); -- 3. Invoice Master Table CREATE TABLE Invoices ( InvoiceID INT IDENTITY(1,1) PRIMARY KEY, InvoiceNumber VARCHAR(50) UNIQUE NOT NULL, InvoiceDate DATETIME NOT NULL DEFAULT GETDATE(), CustomerID INT FOREIGN KEY REFERENCES Customers(CustomerID), SubTotal DECIMAL(18, 2) NOT NULL, TaxRate DECIMAL(5, 2) NOT NULL DEFAULT 0.00, -- Percentage (e.g., 15.00) TaxAmount DECIMAL(18, 2) NOT NULL, GrandTotal DECIMAL(18, 2) NOT NULL ); -- 4. Invoice Line Items Table (Many-to-Many Breakdown) CREATE TABLE InvoiceDetails ( DetailID INT IDENTITY(1,1) PRIMARY KEY, InvoiceID INT FOREIGN KEY REFERENCES Invoices(InvoiceID) ON DELETE CASCADE, ProductID INT FOREIGN KEY REFERENCES Products(ProductID), Quantity INT NOT NULL, UnitPrice DECIMAL(18, 2) NOT NULL, LineTotal AS (Quantity * UnitPrice) PERSISTED ); GO -- Seed Mock Data for Verification INSERT INTO Products (ProductCode, ProductName, UnitPrice, StockQuantity) VALUES ('P1001', 'Wireless Mouse', 25.00, 150), ('P1002', 'Mechanical Keyboard', 85.50, 75), ('P1003', '27-inch 4K Monitor', 349.99, 30); INSERT INTO Customers (CustomerName, ContactNumber, Email) VALUES ('General Cash Customer', '0000000000', 'cash@local.com'), ('Jane Doe', '5551234567', 'jane.doe@example.com'); GO Use code with caution. The Presentation Layer (UI Design)

Effective billing software must handle transaction management and data persistence. Key features include:

When you download a generic "vb.net billing software source code" from GitHub or a code repository, you will need to make modifications: End Sub Usually utilizes System

In the digital age, automation is the key to business efficiency. For developers, particularly those working within the Microsoft ecosystem, creating custom invoicing applications is a common requirement. remains a popular search topic because Visual Basic .NET offers a rapid application development (RAD) environment, making it ideal for creating Windows-based desktop applications .

Public Function SaveBill(customerID As Integer, dtCart As DataTable, paymentMode As String) As Boolean Using transaction As SqlTransaction = con.BeginTransaction() Try ' 1. Insert into tbl_Invoice Dim cmdHeader As New SqlCommand("INSERT INTO tbl_Invoice (InvoiceDate, CustomerID, SubTotal, GST_Amount, GrandTotal, PaymentMode) OUTPUT INSERTED.InvoiceNo VALUES (@date, @cust, @sub, @gst, @grand, @mode)", con, transaction) ' ... add parameters from calculated totals ... Dim newInvoiceNo As Integer = Convert.ToInt32(cmdHeader.ExecuteScalar()) ' 2. Insert each row into tbl_InvoiceDetails & reduce stock For Each row As DataGridViewRow In dtCart.Rows ' Insert details Dim cmdDetail As New SqlCommand("INSERT INTO tbl_InvoiceDetails (InvoiceNo, ProductID, Quantity, Price, GST_Percent, LineTotal) VALUES (@invNo, @pid, @qty, @price, @gst, @lineTotal)", con, transaction) ' ... add parameters ...

: For a more robust enterprise-level tool, this source code supports SQL Server and includes advanced processing power for high-volume transactions. Key Features for Your Project Report Conclusion You might be thinking, “Why not start

A billing system is a (Create, Read, Update, Delete). The core challenge is maintaining data integrity (no duplicate bills, correct tax calculations) and speed (instant search while billing).

Imports System.Data.SqlClient Imports System.Drawing.Printing Public Class FormBilling ' Define your SQL Server database connection string Dim connString As String = "Server=(localdb)\MSSQLLocalDB;Database=BillingDB;Trusted_Connection=True;" Dim conn As New SqlConnection(connString) ' Structure to hold temporary printing data Private invoiceIdToPrint As Integer = 0 Private Sub FormBilling_Load(sender As Object, e As EventArgs) Handles MyBase.Load LoadProducts() ResetForm() End Sub ''' ''' Fetches active items from the database and binds them to the product selection ComboBox. ''' Private Sub LoadProducts() Try Dim query As String = "SELECT ProductID, ProductName, Price FROM Products ORDER BY ProductName ASC" Dim adapter As New SqlDataAdapter(query, conn) Dim dt As New DataTable() adapter.Fill(dt) cmbProducts.DataSource = dt cmbProducts.DisplayMember = "ProductName" cmbProducts.ValueMember = "ProductID" cmbProducts.SelectedIndex = -1 txtPrice.Clear() Catch ex As Exception MessageBox.Show("Error loading products: " & ex.Message, "Database Error", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub ' Update the price field automatically when a product is selected Private Sub cmbProducts_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmbProducts.SelectedIndexChanged If cmbProducts.SelectedIndex <> -1 AndAlso TypeOf cmbProducts.SelectedValue Is DataRowView = False Then Dim drv As DataRowView = CType(cmbProducts.SelectedItem, DataRowView) txtPrice.Text = Convert.ToDecimal(drv("Price")).ToString("F2") txtQuantity.Text = "1" End If End Sub ''' ''' Adds the selected product and quantity into the DataGridView cart. ''' Private Sub btnAddItem_Click(sender As Object, e As EventArgs) Handles btnAddItem.Click If cmbProducts.SelectedIndex = -1 Then MessageBox.Show("Please select a product first.", "Input Validation", MessageBoxButtons.OK, MessageBoxIcon.Warning) Exit Sub End If Dim qty As Integer If Not Integer.TryParse(txtQuantity.Text, qty) OrElse qty <= 0 Then MessageBox.Show("Please enter a valid quantity greater than zero.", "Input Validation", MessageBoxButtons.OK, MessageBoxIcon.Warning) Exit Sub End If Dim prodId As Integer = Convert.ToInt32(cmbProducts.SelectedValue) Dim prodName As String = cmbProducts.Text Dim price As Decimal = Convert.ToDecimal(txtPrice.Text) Dim total As Decimal = price * qty ' Check if product already exists in the cart grid; if so, update quantity Dim itemExists As Boolean = False For Each row As DataGridViewRow In dgvInvoice.Rows If Convert.ToInt32(row.Cells("ProdID").Value) = prodId Then Dim currentQty As Integer = Convert.ToInt32(row.Cells("Qty").Value) row.Cells("Qty").Value = currentQty + qty row.Cells("Total").Value = (currentQty + qty) * price itemExists = True Exit For End If Next ' If item is unique to the current session, add it as a new row If Not itemExists Then dgvInvoice.Rows.Add(prodId, prodName, price.ToString("F2"), qty, total.ToString("F2")) End If CalculateInvoiceTotals() txtQuantity.Text = "1" cmbProducts.SelectedIndex = -1 txtPrice.Clear() End Sub ''' ''' Calculates Subtotal, Taxes, Discounts, and the final Grand Total in real-time. ''' Private Sub CalculateInvoiceTotals() Dim subTotal As Decimal = 0 For Each row As DataGridViewRow In dgvInvoice.Rows subTotal += Convert.ToDecimal(row.Cells("Total").Value) Next Dim taxPercent As Decimal = 0 Decimal.TryParse(txtTax.Text, taxPercent) Dim discountAmt As Decimal = 0 Decimal.TryParse(txtDiscount.Text, discountAmt) Dim taxAmount As Decimal = subTotal * (taxPercent / 100) Dim grandTotal As Decimal = (subTotal + taxAmount) - discountAmt txtSubTotal.Text = subTotal.ToString("F2") txtGrandTotal.Text = grandTotal.ToString("F2") End Sub ' Live calculation events when dynamic variables change Private Sub txtTax_TextChanged(sender As Object, e As EventArgs) Handles txtTax.TextChanged, txtDiscount.TextChanged CalculateInvoiceTotals() End Sub ''' ''' Validates UI input, saves transactions safely to database tables, updates stock, and prints. ''' Private Sub btnSavePrint_Click(sender As Object, e As EventArgs) Handles btnSavePrint.Click If String.IsNullOrWhiteSpace(txtCustomerName.Text) Then MessageBox.Show("Customer Name is required.", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Warning) Exit Sub End If If dgvInvoice.Rows.Count = 0 Then MessageBox.Show("Cart is empty. Please add items to process the invoice.", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Warning) Exit Sub End If Dim insertedInvoiceId As Integer = 0 ' Initialize SQL transaction logic for accurate state commitment Using connection As New SqlConnection(connString) connection.Open() Using transaction As SqlTransaction = connection.BeginTransaction() Try ' Insert Master Invoice Records Dim queryInvoice As String = "INSERT INTO Invoices (CustomerName, SubTotal, TaxAmount, Discount, GrandTotal) " & "OUTPUT INSERTED.InvoiceID " & "VALUES (@Customer, @Sub, @Tax, @Disc, @Grand);" Using cmdInv As New SqlCommand(queryInvoice, connection, transaction) cmdInv.Parameters.AddWithValue("@Customer", txtCustomerName.Text.Trim()) cmdInv.Parameters.AddWithValue("@Sub", Convert.ToDecimal(txtSubTotal.Text)) Dim taxPercent As Decimal = 0 Decimal.TryParse(txtTax.Text, taxPercent) Dim calculatedTaxObj As Decimal = Convert.ToDecimal(txtSubTotal.Text) * (taxPercent / 100) cmdInv.Parameters.AddWithValue("@Tax", calculatedTaxObj) cmdInv.Parameters.AddWithValue("@Disc", Convert.ToDecimal(txtDiscount.Text)) cmdInv.Parameters.AddWithValue("@Grand", Convert.ToDecimal(txtGrandTotal.Text)) insertedInvoiceId = CInt(cmdInv.ExecuteScalar()) End Using ' Insert Item Details & Update Live Inventory Counts For Each row As DataGridViewRow In dgvInvoice.Rows Dim pid As Integer = Convert.ToInt32(row.Cells("ProdID").Value) Dim prc As Decimal = Convert.ToDecimal(row.Cells("Price").Value) Dim qty As Integer = Convert.ToInt32(row.Cells("Qty").Value) Dim tot As Decimal = Convert.ToDecimal(row.Cells("Total").Value) ' 1. Write transactional line item records Dim queryDetails As String = "INSERT INTO InvoiceDetails (InvoiceID, ProductID, Price, Quantity, Total) " & "VALUES (@InvID, @ProdID, @Price, @Qty, @Tot);" Using cmdDet As New SqlCommand(queryDetails, connection, transaction) cmdDet.Parameters.AddWithValue("@InvID", insertedInvoiceId) cmdDet.Parameters.AddWithValue("@ProdID", pid) cmdDet.Parameters.AddWithValue("@Price", prc) cmdDet.Parameters.AddWithValue("@Qty", qty) cmdDet.Parameters.AddWithValue("@Tot", tot) cmdDet.ExecuteNonQuery() End Using ' 2. Deduct active stock levels safely Dim queryStock As String = "UPDATE Products SET StockQty = StockQty - @Qty WHERE ProductID = @ProdID" Using cmdStock As New SqlCommand(queryStock, connection, transaction) cmdStock.Parameters.AddWithValue("@Qty", qty) cmdStock.Parameters.AddWithValue("@ProdID", pid) cmdStock.ExecuteNonQuery() End Using Next ' Commit structural items if both operations pass successfully transaction.Commit() invoiceIdToPrint = insertedInvoiceId MessageBox.Show("Invoice saved successfully with ID: " & invoiceIdToPrint, "Success", MessageBoxButtons.OK, MessageBoxIcon.Information) ' Trigger Printing Routine TriggerReceiptPrinting() ResetForm() Catch ex As Exception transaction.Rollback() MessageBox.Show("Transaction failed and was rolled back: " & ex.Message, "System Error", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Using End Using End Sub ''' ''' Configures standard .NET printing subroutines. ''' Private Sub TriggerReceiptPrinting() Try Use code with caution.

CREATE TABLE Products ( ProductID INT PRIMARY KEY IDENTITY, PName VARCHAR(100), Price DECIMAL(18, 2), Stock INT ); CREATE TABLE Invoices ( InvoiceID INT PRIMARY KEY IDENTITY, CustomerName VARCHAR(100), InvoiceDate DATE, TotalAmount DECIMAL(18, 2) ); Use code with caution. 3. Setting up the Connection (Connection Class)

This article will serve as a deep dive into the architecture, features, database design, and actual code structure of a professional billing software built with VB.NET.