Skip to main content
The Inventory Management system provides real-time synchronization between managers and their sales team, ensuring everyone has up-to-date information on product availability and sales performance.

Overview

Inventory management works differently based on your role:

Manager View

Add items, set quantities and profit margins, view team-wide sales, and delete products

Salesperson View

View assigned inventory, log sales, track personal performance, and see remaining stock

Inventory Data Model

Each inventory item contains the following information:
public class InventoryItem {
    private String itemName;
    private int total_available;  // Total quantity available
    private int sold;             // Quantity sold
    private int profit;           // Profit per unit
    
    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;
    }
}
Source: InventoryItem.java:1-42
The profit field represents the profit margin per unit sold, not the total profit. Total profit is calculated as sold * profit.

Manager Inventory Management

Adding Inventory Items

Managers can add new products to the inventory, which automatically propagates to all salespersons on their team.
1

Access Add Item Dialog

From the Manager dashboard, tap the floating action button (FAB) in the bottom-right corner.
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        // Show dialog to add item
    }
});
Source: ManagerMain.java:114-117
2

Enter Item Details

In the dialog, provide:
  • Item Name: Product name or SKU
  • Quantity: Initial available quantity
  • Profit per Unit: Profit margin for each item sold
The quantity picker uses a MeterView component for easy number selection.
3

Validate and Save

The system validates all fields are filled:
String item = itemName.getText().toString();
String q1 = String.valueOf(q.getValue());
int profitAmount = Integer.parseInt(profit.getText().toString());

if(TextUtils.isEmpty(item) || TextUtils.isEmpty(q1)) {
    Toast.makeText(getApplicationContext(), 
        "Please fill all the details!", 
        Toast.LENGTH_LONG).show();
} else {
    int quant = Integer.parseInt(q1);
    it = new InventoryItem(item, quant, 0, profitAmount);
    
    String key = databaseRef.child(id).child("Inventory").push().getKey();
    databaseRef.child(id).child("Inventory").child(key).setValue(it);
}
Source: ManagerMain.java:137-152
4

Auto-Distribution to Team

The item is automatically added to all salespersons under this manager:
final DatabaseReference databaseRef1 = FirebaseDatabase.getInstance()
    .getReference("Salesperson");
databaseRef1.addListenerForSingleValueEvent(new ValueEventListener() {
    @Override
    public void onDataChange(@NonNull DataSnapshot dataSnapshot2) {
        for(DataSnapshot snapshot1 : dataSnapshot2.getChildren()) {
            SalesPerson sp1 = snapshot1.getValue(SalesPerson.class);
            String salesperson_id = snapshot1.getKey();
            
            if(sp1.getManagerName().equals(ManagerName)) {
                String key1 = databaseRef1.child(salesperson_id)
                    .child("Inventory").push().getKey();
                databaseRef1.child(salesperson_id)
                    .child("Inventory").child(key1).setValue(it);
            }
        }
    }
});
Source: ManagerMain.java:196-218
All salespersons on your team receive the new item instantly with zero sales and the full available quantity.

Viewing Inventory

The Manager dashboard displays all inventory items in a RecyclerView with detailed information:
mRecyclerView = findViewById(R.id.items_list);
final ArrayList<InventoryItem> list = new ArrayList<>();

databaseRef.child(id).child("Inventory")
    .addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
                InventoryItem it1 = snapshot.getValue(InventoryItem.class);
                list.add(it1);
            }
            mAdapter = new InventoryAdapter(getApplicationContext(), list, ManagerMain.this);
            mRecyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
            mRecyclerView.setAdapter(mAdapter);
        }
    });
Source: ManagerMain.java:92-111

Inventory Item Display

Each inventory item card shows:

Item Name

Product or SKU identifier

Total Available

Initial quantity added to inventory

Sold

Total units sold across all salespersons

Unallocated

Remaining available units (Total - Sold)

Total Profit

Calculated as: Profit per unit × Sold quantity

Progress Bar

Visual indicator of sales progress
Implementation in InventoryAdapter.java:69-78:
holder.total.setText(String.valueOf(item.getTotal_available()));
holder.sold.setText(String.valueOf(item.getSold()));
holder.unalloted.setText(String.valueOf(item.getTotal_available() - item.getSold()));
holder.itemName.setText(item.getItemName());
holder.progressBar.setMax(item.getTotal_available());
holder.progressBar.setProgress(item.getSold());
holder.profitText.setText(String.valueOf(item.getProfit() * item.getSold()));

Deleting Inventory Items

Managers can remove items from inventory:
1

Tap Delete Icon

Each inventory item has a delete icon. Tapping it shows a confirmation dialog.
2

Confirm Deletion

A warning dialog appears:
new FancyAlertDialog.Builder(activity)
    .setTitle("Warning!!!")
    .setBackgroundColor(Color.parseColor("#5002a4"))
    .setMessage("Do you really want to delete this item?")
    .setNegativeBtnText("No")
    .setPositiveBtnText("Yes")
    .OnPositiveClicked(new FancyAlertDialogListener() {
        @Override
        public void OnClick() {
            // Delete item
        }
    })
    .build();
Source: InventoryAdapter.java:93-104
3

Cascading Deletion

The item is removed from:
  1. Manager’s inventory
  2. All salespersons’ inventories who work under this manager
// Delete from manager
snapshot.getRef().removeValue();

// Delete from all salespersons
DatabaseReference databaseRef1 = FirebaseDatabase.getInstance()
    .getReference("Salesperson");
databaseRef1.addListenerForSingleValueEvent(new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot dataSnapshot) {
        for(DataSnapshot dataSnapshot1 : dataSnapshot.getChildren()){
            String id1 = dataSnapshot1.getKey();
            databaseRef2.child(id1).child("Inventory")
                .addListenerForSingleValueEvent(new ValueEventListener() {
                    // Find and delete matching item
                });
        }
    }
});
Source: InventoryAdapter.java:124-161
Deletion is permanent and cannot be undone. All sales history for that item will be preserved in analytics but the item cannot be sold anymore.

Refresh Inventory

Pull down on the inventory list to refresh and sync with the latest data:
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
    @Override
    public void onRefresh() {
        updateList(id, role, false);
        swipeRefreshLayout.setRefreshing(false);
    }
});
Source: ManagerMain.java:75-81

Salesperson Inventory Management

Viewing Assigned Inventory

Salespersons see their personal inventory with items assigned by their manager:
databaseReference = FirebaseDatabase.getInstance().getReference(role);
mRecyclerView = findViewById(R.id.items_list1);

list = new ArrayList<>();
databaseReference.child(id).child("Inventory")
    .addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
            for(DataSnapshot snapshot : dataSnapshot.getChildren()){
                InventoryItem it1 = snapshot.getValue(InventoryItem.class);
                list.add(it1);
            }
            mAdapter = new SalespersonInventoryAdapter(getApplicationContext(), list);
            mRecyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
            mRecyclerView.setAdapter(mAdapter);
        }
    });
Source: SalespersonMain.java:268-287

Recording Sales

Salespersons log sales through an intuitive dialog:
1

Open Selling Dialog

Tap the floating action button on the Salesperson dashboard:
fab.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        ArrayList<String> itemlist = getItemList(id, role);
        // Show selling dialog
    }
});
Source: SalespersonMain.java:93-97
2

Select Item and Quantity

The dialog provides:
  • AutoCompleteTextView: Search and select from available items
  • MeterView: Set quantity sold
final AutoCompleteTextView autoCompleteTextView;
final MeterView numberPicker;

ArrayAdapter<String> adapter = new ArrayAdapter<String>(
    mView.getContext(),
    R.layout.support_simple_spinner_dropdown_item,
    itemlist
);
autoCompleteTextView.setThreshold(1);
autoCompleteTextView.setAdapter(adapter);
Source: SalespersonMain.java:107-110
3

Validation

The system validates the sale:
sold = numberPicker.getValue();
final String itemName = autoCompleteTextView.getText().toString();

if(TextUtils.isEmpty(itemName) || sold == 0) {
    Toast.makeText(getApplicationContext(),
        "Please fill all the details!", 
        Toast.LENGTH_LONG).show();
}

// Check if sold quantity exceeds available
if(it1.getTotal_available() < sold) {
    Toast.makeText(getApplicationContext(), 
        "Sold can't be greater than items remaining!", 
        Toast.LENGTH_LONG).show();
    sold = 0;
}
Source: SalespersonMain.java:166-169
4

Update Inventory

The sale updates multiple locations:1. Salesperson’s sold count:
InventoryItem it = new InventoryItem(
    itemName,
    it1.getTotal_available(),
    sold + it1.getSold(),  // Add to existing sold
    it1.getProfit()
);
databaseReference1.child(id).child("Inventory")
    .child(snapshot1.getKey()).setValue(it);
Source: SalespersonMain.java:171-1722. Manager’s sold count:
InventoryItem itNew = new InventoryItem(
    itemName,
    it1.getTotal_available(),
    it1.getSold() + sold,  // Increment manager's sold
    it1.getProfit()
);
databaseReference.child(snapshot.getKey())
    .child("Inventory").child(snapshot1.getKey()).setValue(itNew);
Source: SalespersonMain.java:342-3433. All team members’ available quantity:
InventoryItem it = new InventoryItem(
    itemName,
    it1.getTotal_available() - sold,  // Reduce available for all
    it1.getSold(),
    it1.getProfit()
);
Source: SalespersonMain.java:208
5

Graph Update

The sale is recorded in the analytics graph:
if(sold > 0) {
    GraphSalesperson.create(
        String.valueOf(it1.getProfit() * sold), 
        salespersonName
    );
}
Source: SalespersonMain.java:179-186

Real-Time Synchronization

The inventory system maintains consistency across all users:
When a salesperson records a sale:
  1. Their inventory increases the “sold” count
  2. Manager’s inventory increases the “sold” count for that item
  3. All team members see reduced “available” quantity
  4. Analytics graphs update with the new sale data
  5. Leaderboard recalculates performance metrics
This happens in real-time through Firebase listeners, ensuring everyone has current information.

Inventory Item Details

Tap any inventory item to view detailed information:
holder.itemView.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        Intent intent = new Intent(context, ProductSpecificDetails.class);
        intent.putExtra("itemName", item.getItemName());
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    }
});
Source: InventoryAdapter.java:79-86 The ProductSpecificDetails activity shows:
  • Complete sales history
  • Performance by salesperson
  • Profit breakdown
  • Availability trends

Common Workflows

  1. Tap the FAB button
  2. Enter item name: “Laptop Model X”
  3. Set quantity: 50 units
  4. Set profit: $100 per unit
  5. Tap OK
  6. Item appears on your dashboard and all salespersons’ dashboards
  1. Tap the FAB button
  2. Type item name in search field
  3. Select from dropdown
  4. Use number picker to set quantity sold: 3 units
  5. Tap OK
  6. Your sold count increases by 3
  7. Available quantity decreases by 3 for all team members
  8. Manager sees updated sold count
  9. Graph records your profit ($300 in this example)
  1. View inventory list
  2. Check “Sold” column for each item
  3. Review progress bars for visual performance indicators
  4. Tap item for detailed breakdown by salesperson
  5. Navigate to Analytics for profit distribution graphs
  1. Open your dashboard
  2. View “Total Available” for each item
  3. This reflects current stock after all team sales
  4. Pull down to refresh if needed
  5. Items with low stock appear with low available counts

Best Practices

For Managers

  • Add items with realistic quantities
  • Set accurate profit margins
  • Monitor low stock items regularly
  • Delete discontinued items promptly

For Salespersons

  • Log sales immediately after closing
  • Double-check quantities before submitting
  • Monitor available stock before promising customers
  • Refresh inventory before major sales calls
Use the pull-to-refresh gesture frequently during high-sales periods to ensure you have the latest inventory data.

Build docs developers (and LLMs) love