Vb.net Billing Software Source Code

Deep Dive: Architecting a Billing Software System in VB.NET

8. Recommendations before adoption

  1. Run static analysis and security scan (e.g., SonarQube, Roslyn analyzers).
  2. Search the codebase for secrets and remove/rotate any found.
  3. Replace raw SQL concatenation with parameterized queries or ORM.
  4. Implement proper password hashing and role-based authorization.
  5. Add logging, error handling, and input validation.
  6. Establish licensing compliance and document third-party components.
  7. Write unit tests for core billing calculations (tax, discounts, totals).
  8. If long-term use is planned, refactor toward layered architecture and introduce CI/CD.

Customizing the Source Code for Your Business

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

  1. Barcode Scanning: Add a textbox that searches product by barcode when a scanner is used.
  2. Digital Signature & QR Code: Use QRCoder library to embed payment links or invoice verification codes.
  3. Email Invoicing: Use SmtpClient to send PDF invoices directly from the app.
  4. Cloud Backup: Schedule automatic SQL Server backups and upload to Google Drive or FTP using .NET libraries.
  5. Role-Based Access: Create Admin, Billing Operator, and Accounts logins with different permissions.

4. Saving the Full Invoice (Master + Details)

Private Sub SaveInvoice()
    OpenDB()
    Dim transaction As SqlTransaction = conn.BeginTransaction()
    Try
        ' 1. Insert into Invoice Master
        Dim invoiceNo As Integer = GetNextInvoiceNumber() ' custom function
        Dim masterQuery As String = "INSERT INTO tbl_Invoice_Master VALUES(@invNo, @date, @custID, @sub, @discPct, @tax, @grand)"
        cmd = New SqlCommand(masterQuery, conn, transaction)
        cmd.Parameters.AddWithValue("@invNo", invoiceNo)
        cmd.Parameters.AddWithValue("@date", DateTime.Now)
        cmd.Parameters.AddWithValue("@custID", cmbCustomer.SelectedValue)
        cmd.Parameters.AddWithValue("@sub", lblSubtotal.Text)
        cmd.Parameters.AddWithValue("@discPct", txtDiscountPercent.Text)
        cmd.Parameters.AddWithValue("@tax", lblTax.Text)
        cmd.Parameters.AddWithValue("@grand", lblGrandTotal.Text)
        cmd.ExecuteNonQuery()
    ' 2. Insert details
    For Each row As DataGridViewRow In dgvBill.Rows
        If row.IsNewRow Then Continue For
        Dim detailQuery As String = "INSERT INTO tbl_Invoice_Details (InvoiceNo, ProductID, Quantity, Rate, Amount) 
                                     VALUES(@invNo, @pid, @qty, @rate, @amt)"
        cmd = New SqlCommand(detailQuery, conn, transaction)
        cmd.Parameters.AddWithValue("@invNo", invoiceNo)
        cmd.Parameters.AddWithValue("@pid", row.Cells("ProductID").Value)
        cmd.Parameters.AddWithValue("@qty", row.Cells("Quantity").Value)
        cmd.Parameters.AddWithValue("@rate", row.Cells("Rate").Value)
        cmd.Parameters.AddWithValue("@amt", row.Cells("Amount").Value)
        cmd.ExecuteNonQuery()
' Update stock
        Dim updateStock As String = "UPDATE tbl_Product SET StockQuantity = StockQuantity - @qty WHERE ProductID = @pid"
        cmd = New SqlCommand(updateStock, conn, transaction)
        cmd.Parameters.AddWithValue("@qty", row.Cells("Quantity").Value)
        cmd.Parameters.AddWithValue("@pid", row.Cells("ProductID").Value)
        cmd.ExecuteNonQuery()
    Next
transaction.Commit()
    MessageBox.Show("Invoice #" & invoiceNo & " saved successfully.")
    ClearBillForm()
Catch ex As Exception
    transaction.Rollback()
    MessageBox.Show("Failed: " & ex.Message)
Finally
    CloseDB()
End Try

End Sub


Table Structure (SQL Scripts)

-- 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 ); vb.net billing software source code

-- 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) ); Deep Dive: Architecting a Billing Software System in VB

-- 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) ); Run static analysis and security scan (e