Skip to main content

Overview

The Sales Management App uses three primary data models to represent users and inventory data. These models are designed to work seamlessly with Firebase Realtime Database and follow Java POJO (Plain Old Java Object) patterns.

SalesManager Model

The SalesManager class represents a sales manager user who oversees a team of salespeople and manages inventory.

Class Definition

package project.avishkar.salesmanagement;

import java.util.ArrayList;

public class SalesManager {
    private String name, number, password, email, orgName;
    private ArrayList<InventoryItem> inventoryItems;

    public SalesManager(){}
    
    public SalesManager(String name, String number, String password, 
                        String email, String orgName){
        this.name = name;
        this.number = number;
        this.password = password;
        this.email = email;
        this.orgName = orgName;
        this.inventoryItems = new ArrayList<>();
    }

    public String getEmail() {
        return email;
    }

    public String getOrgName() {
        return orgName;
    }

    public String getName() {
        return name;
    }

    public String getNumber() {
        return number;
    }

    public String getPassword() {
        return password;
    }
}

Properties

name
String
required
The full name of the sales managerExample: "John Doe"
number
String
required
Contact phone number of the managerExample: "+1234567890"
password
String
required
User password (should be hashed in production)
Current implementation stores passwords. Recommended to use Firebase Authentication exclusively instead.
email
String
required
Email address for authentication and communicationExample: "[email protected]"
orgName
String
required
Organization or company name that the manager representsExample: "Acme Sales Corp"
inventoryItems
ArrayList<InventoryItem>
List of inventory items managed by this sales managerInitialized as an empty ArrayList in the constructor

Usage Example

// Create a new sales manager instance
SalesManager manager = new SalesManager(
    "John Doe",
    "+1234567890",
    "securePassword123",
    "[email protected]",
    "Acme Sales Corp"
);

// Save to Firebase Realtime Database
String userId = FirebaseAuth.getInstance().getCurrentUser().getUid();
FirebaseDatabase.getInstance()
    .getReference("salesManagers")
    .child(userId)
    .setValue(manager);

SalesPerson Model

The SalesPerson class represents a salesperson who reports to a sales manager and tracks their own inventory sales.

Class Definition

package project.avishkar.salesmanagement;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import org.w3c.dom.Text;

import java.util.ArrayList;

public class SalesPerson {
    private String name, number, managerName, password, emailId;
    private ArrayList<InventoryItem> inventoryItems;

    public SalesPerson(){}
    
    public SalesPerson(String name, String number, String password, 
                       String managerName, String Email) {
        this.name = name;
        this.number = number;
        this.password = password;
        this.managerName = managerName;
        this.emailId = Email;
        this.inventoryItems = new ArrayList<>();
    }

    public String getEmailId() {
        return emailId;
    }
    
    public String getName() {
        return name;
    }

    public String getNumber() {
        return number;
    }

    public String getManagerName() {
        return managerName;
    }

    public ArrayList<InventoryItem> getInventoryItems() {
        return inventoryItems;
    }

    public String getPassword() {
        return password;
    }
}

Properties

name
String
required
The full name of the salespersonExample: "Jane Smith"
number
String
required
Contact phone number of the salespersonExample: "+1234567891"
managerName
String
required
Name of the sales manager this person reports toExample: "John Doe"
This creates a relationship between salesperson and manager. Consider using manager UID for better data integrity.
password
String
required
User password for authentication
Should be managed through Firebase Authentication instead of storing directly.
emailId
String
required
Email address for authentication and communicationExample: "[email protected]"
inventoryItems
ArrayList<InventoryItem>
List of inventory items assigned to and tracked by this salespersonInitialized as an empty ArrayList. Items are added as the salesperson receives inventory.

Usage Example

// Create a new salesperson instance
SalesPerson salesperson = new SalesPerson(
    "Jane Smith",
    "+1234567891",
    "securePassword456",
    "John Doe",  // Manager's name
    "[email protected]"
);

// Save to Firebase Realtime Database
String userId = FirebaseAuth.getInstance().getCurrentUser().getUid();
FirebaseDatabase.getInstance()
    .getReference("salesPeople")
    .child(userId)
    .setValue(salesperson);

InventoryItem Model

The InventoryItem class represents a product in the inventory with tracking for availability, sales, and profit.

Class Definition

package project.avishkar.salesmanagement;

public class InventoryItem {
    private String itemName;
    private int total_available, sold, profit;

    public InventoryItem(){
    }

    public InventoryItem(String itemName, int total_available, int sold, int profit)
    {
        this.itemName = itemName;
        this.total_available = total_available;
        this.sold = sold;
        this.profit = profit;
    }

    public InventoryItem(String itemName, int total_available, int sold)
    {
        this.itemName = itemName;
        this.total_available = total_available;
        this.sold = sold;
        this.profit = (this.total_available - this.sold);
    }

    public String getItemName() { 
        return itemName; 
    }

    public int getTotal_available() {
        return total_available;
    }

    public int getSold() {
        return sold;
    }

    public int getProfit() {
        return profit;
    }
}

Properties

itemName
String
required
Name or description of the inventory itemExample: "Widget Pro 2000", "Premium Package"
total_available
int
required
Total quantity of items available in inventoryExample: 100
sold
int
required
Number of items sold from this inventoryExample: 25
profit
int
Calculated profit or remaining inventoryCalculation: When using 3-parameter constructor, profit = total_available - soldExample: 75 (if 100 available and 25 sold)
The naming suggests this represents profit, but the calculation shows it’s actually remaining inventory. Consider renaming to remaining for clarity.

Constructors

The InventoryItem class provides three constructors:
public InventoryItem()
Empty constructor required by Firebase for data deserialization.
public InventoryItem(String itemName, int total_available, int sold, int profit)
Allows explicit setting of all fields including profit. Use when profit is pre-calculated or represents actual monetary profit.
public InventoryItem(String itemName, int total_available, int sold)
Automatically calculates profit as total_available - sold. Use for simple inventory tracking.

Usage Examples

// Using auto-calculation constructor
InventoryItem item1 = new InventoryItem(
    "Widget Pro 2000",
    100,  // total available
    25    // sold
);
// profit automatically calculated as 75

// Using explicit profit constructor
InventoryItem item2 = new InventoryItem(
    "Premium Package",
    50,   // total available
    30,   // sold
    2000  // explicit profit value (e.g., monetary profit)
);

// Save to Firebase
FirebaseDatabase.getInstance()
    .getReference("inventory")
    .push()
    .setValue(item1);

Data Model Relationships

Best Practices

Use Firebase Auth

Avoid storing passwords in data models. Use Firebase Authentication for all password management.

Add Setters

Current models only have getters. Add setter methods to enable field updates after object creation.

Use UIDs for Relations

Instead of storing managerName as String, use manager’s Firebase UID for reliable relationships.

Add Validation

Implement validation methods to ensure data integrity (e.g., email format, non-negative inventory counts).
Consider these enhancements for production applications:

1. Add Setter Methods

public class SalesManager {
    // ... existing fields ...
    
    // Add setters
    public void setName(String name) {
        this.name = name;
    }
    
    public void setEmail(String email) {
        this.email = email;
    }
    
    public void setInventoryItems(ArrayList<InventoryItem> items) {
        this.inventoryItems = items;
    }
    
    public void addInventoryItem(InventoryItem item) {
        this.inventoryItems.add(item);
    }
}

2. Implement Parcelable

For passing objects between activities:
public class InventoryItem implements Parcelable {
    // ... existing fields ...
    
    protected InventoryItem(Parcel in) {
        itemName = in.readString();
        total_available = in.readInt();
        sold = in.readInt();
        profit = in.readInt();
    }
    
    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(itemName);
        dest.writeInt(total_available);
        dest.writeInt(sold);
        dest.writeInt(profit);
    }
    
    public static final Creator<InventoryItem> CREATOR = new Creator<InventoryItem>() {
        @Override
        public InventoryItem createFromParcel(Parcel in) {
            return new InventoryItem(in);
        }
        
        @Override
        public InventoryItem[] newArray(int size) {
            return new InventoryItem[size];
        }
    };
    
    @Override
    public int describeContents() {
        return 0;
    }
}

3. Add Data Validation

public class SalesManager {
    // ... existing code ...
    
    public boolean isValid() {
        return name != null && !name.isEmpty()
            && email != null && isValidEmail(email)
            && number != null && !number.isEmpty()
            && orgName != null && !orgName.isEmpty();
    }
    
    private boolean isValidEmail(String email) {
        return email.matches("^[A-Za-z0-9+_.-]+@(.+)$");
    }
}

Next Steps

Architecture

Learn about the overall application architecture

Firebase Setup

Configure Firebase to work with these data models

Build docs developers (and LLMs) love