Vb.net Billing Software Source Code

Automatically deduct stock levels when an invoice is generated. C. Invoicing Module (The Core) This is where the main logic resides. Calculation Logic: Calculates subtotal, tax ( VAT), discounts, and total amount.

Imports System.Data.SqlClient Public Class frmBilling Private taxRate As Double = 0.15 ' 15% Tax Rate Private subTotalSum As Double = 0.0 Private Sub frmBilling_Load(sender As Object, e As EventArgs) Handles MyBase.Load InitializeCartGrid() End Sub ' Initialize DataGridView columns programmatically Private Sub InitializeCartGrid() dgvBillItems.Columns.Clear() dgvBillItems.Columns.Add("ProdID", "Product ID") dgvBillItems.Columns.Add("ProdName", "Product Name") dgvBillItems.Columns.Add("Price", "Unit Price") dgvBillItems.Columns.Add("Qty", "Quantity") dgvBillItems.Columns.Add("Total", "SubTotal") End Sub ' Fetch product info automatically when Product ID is entered Private Sub txtProductID_Leave(sender As Object, e As EventArgs) Handles txtProductID.Leave If String.IsNullOrEmpty(txtProductID.Text) Then Exit Sub Try OpenConnection() Dim query As String = "SELECT ProductName, Price, StockQuantity FROM Products WHERE ProductID = @ID" Using cmd As New SqlCommand(query, conn) cmd.Parameters.AddWithValue("@ID", Convert.ToInt32(txtProductID.Text)) Using reader As SqlDataReader = cmd.ExecuteReader() If reader.Read() Then Dim stock As Integer = Convert.ToInt32(reader("StockQuantity")) If stock <= 0 Then MessageBox.Show("Product out of stock!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning) Exit Sub End If txtProductName.Text = reader("ProductName").ToString() txtPrice.Text = reader("Price").ToString() Else MessageBox.Show("Product not found.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error) End If End Using End Using Catch ex As Exception MessageBox.Show("Error fetching product: " & ex.Message) Finally CloseConnection() End Try End Sub ' Add item to the billing cart Private Sub btnAddToCart_Click(sender As Object, e As EventArgs) Handles btnAddToCart.Click If String.IsNullOrEmpty(txtProductName.Text) Or String.IsNullOrEmpty(txtQuantity.Text) Then MessageBox.Show("Please select a product and enter quantity.") Exit Sub End If Dim price As Double = Convert.ToDouble(txtPrice.Text) Dim qty As Integer = Convert.ToInt32(txtQuantity.Text) Dim total As Double = price * qty ' Append row to DataGridView dgvBillItems.Rows.Add(txtProductID.Text, txtProductName.Text, price, qty, total) ' Update aggregate values CalculateTotals(total) ClearInputFields() End Sub ' Calculate aggregate values dynamically Private Sub CalculateTotals(ByVal newAmount As Double) subTotalSum += newAmount Dim taxAmount As Double = subTotalSum * taxRate Dim grandTotal As Double = subTotalSum + taxAmount lblSubTotal.Text = subTotalSum.ToString("N2") lblTax.Text = taxAmount.ToString("N2") lblGrandTotal.Text = grandTotal.ToString("N2") End Sub ' Clear entry fields for next item Private Sub ClearInputFields() txtProductID.Clear() txtProductName.Clear() txtPrice.Clear() txtQuantity.Clear() txtProductID.Focus() End Sub ' Save transaction to database and adjust inventory Private Sub btnGenerateInvoice_Click(sender As Object, e As EventArgs) Handles btnGenerateInvoice.Click If dgvBillItems.Rows.Count = 0 Then MessageBox.Show("Cart is empty.") Exit Sub End If Try OpenConnection() ' 1. Insert into Invoices Table Dim invQuery As String = "INSERT INTO Invoices (CustomerName, TotalAmount, TaxAmount, GrandTotal) " & "VALUES (@Cust, @Total, @Tax, @Grand); SELECT SCOPE_IDENTITY();" Dim invoiceId As Integer Dim taxAmount As Double = subTotalSum * taxRate Dim grandTotal As Double = subTotalSum + taxAmount Using cmd As New SqlCommand(invQuery, conn) cmd.Parameters.AddWithValue("@Cust", If(String.IsNullOrEmpty(txtCustomerName.Text), "Walk-in Customer", txtCustomerName.Text)) cmd.Parameters.AddWithValue("@Total", subTotalSum) cmd.Parameters.AddWithValue("@Tax", taxAmount) cmd.Parameters.AddWithValue("@Grand", grandTotal) invoiceId = Convert.ToInt32(cmd.ExecuteScalar()) End Using ' 2. Loop Cart to Insert Items and Deduct Inventory Stock For Each row As DataGridViewRow In dgvBillItems.Rows If row.IsNewRow Then Continue For Dim prodId As Integer = Convert.ToInt32(row.Cells("ProdID").Value) Dim price As Double = Convert.ToDouble(row.Cells("Price").Value) Dim qty As Integer = Convert.ToInt32(row.Cells("Qty").Value) Dim subTot As Double = Convert.ToDouble(row.Cells("Total").Value) ' Insert details Dim itemQuery As String = "INSERT INTO InvoiceItems (InvoiceID, ProductID, Quantity, UnitPrice, SubTotal) " & "VALUES (@InvID, @ProdID, @Qty, @Price, @Sub);" Using cmdItem As New SqlCommand(itemQuery, conn) cmdItem.Parameters.AddWithValue("@InvID", invoiceId) cmdItem.Parameters.AddWithValue("@ProdID", prodId) cmdItem.Parameters.AddWithValue("@Qty", qty) cmdItem.Parameters.AddWithValue("@Price", price) cmdItem.Parameters.AddWithValue("@Sub", subTot) cmdItem.ExecuteNonQuery() End Using ' Deduct stock inventory Dim stockQuery As String = "UPDATE Products SET StockQuantity = StockQuantity - @Qty WHERE ProductID = @ProdID" Using cmdStock As New SqlCommand(stockQuery, conn) cmdStock.Parameters.AddWithValue("@Qty", qty) cmdStock.Parameters.AddWithValue("@ProdID", prodId) cmdStock.ExecuteNonQuery() End Using Next MessageBox.Show("Invoice #" & invoiceId & " generated successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information) ResetForm() Catch ex As Exception MessageBox.Show("Transaction failed: " & ex.Message, "Database Error", MessageBoxButtons.OK, MessageBoxIcon.Error) Finally CloseConnection() End Try End Sub ' Clear entire form status for the next customer order Private Sub ResetForm() dgvBillItems.Rows.Clear() txtCustomerName.Clear() subTotalSum = 0.0 lblSubTotal.Text = "0.00" lblTax.Text = "0.00" lblGrandTotal.Text = "0.00" ClearInputFields() End Sub End Class Use code with caution. 🛠️ Essential Software Optimizations

This SDK allows you to treat an Excel file as a template and populate it with data from your billing system. The SDK then converts the spreadsheet into a professional invoice PDF . This is a very flexible approach because non-developers can design the invoice's layout directly in Excel. vb.net billing software source code

' 4. Grand Footer Summary calculation panel elements section block layoutcoordinateY += 15graphicEngine.DrawString("-----------------------------------------------------", fontNormal, Brushes.Black, coordinateX, coordinateY)coordinateY += rowOffset

VB.NET remains a powerful tool for rapid application development (RAD), especially for small business tools. By combining a clean UI with a structured SQL backend, you can create a reliable billing system tailored to specific needs. Automatically deduct stock levels when an invoice is

Building a Complete VB.NET Billing Software: Step-by-Step Architecture and Source Code

This repository provides a complete point-of-sale system designed for shops, built entirely with VB.NET. The project includes SQL database scripts for easy setup. This is a very flexible approach because non-developers

:

Understanding your database choice is crucial when selecting source code:

| Table | Purpose | | :--- | :--- | | | Store login credentials and access levels | | Products | Product information including name, price, stock quantity, and category | | Customers | Customer profile data including contact information | | Categories | Product categorization for organization | | Invoices | Master record of each transaction—date, customer ID, total amount | | Invoice_Items | Line items for each invoice—product ID, quantity, unit price, subtotal | | Settings | System-wide settings including tax rates, company information |