workPro Documentation
Downloads & Setup
OFFLINE_DATA_DOWNLOAD.md

Offline Data Download System

Overview

The WorkPro mobile app automatically downloads essential data to enable offline functionality. This document describes what data is downloaded, when it's triggered, and how it's stored.


Data Downloaded to Android

1. DROPDOWN DATA

API Endpoint: /workpro/webview/api/dropdowns.php

Downloaded automatically when the main page loads (if no data exists or data is older than 24 hours).

# Data Type Source Table Fields Downloaded Grouping Limit
1 Vendors vendor id, name Flat list 10
2 Projects project id, name, vendor_id By vendor 50
3 Data Centers (DCs) boq (distinct) id, name, vendor_id, project_id By vendor_project 100
4 Activities boq (distinct) id, name, dc_id By dc 200
5 Schedules boq (distinct) id, name, activity_id By activity 500
6 Feeders boq (distinct) id, name, schedule_id By schedule 1000
7 BOQ Items boq + item JOIN id, boq_id, item_code, name, uom, feeder_id By feeder No limit
8 MSPs msp id, name Flat list (global) 100

Data Filtering:

  • Data is filtered based on user's assigned vendorId, projectId, and dcId
  • This minimizes download size by only fetching data the user is authorized to access

Data Hierarchy:

Vendor → Project → DC → Activity → Schedule → Feeder → Item
                                                    ↓
                                                   MSP (global)

2. OFFLINE HTML PAGES

API Endpoint: /workpro/webview/api/offline-pages.php

Downloaded in background after page loads (if not already cached).

# Page Description Purpose
1 Dashboard index.php Main menu when offline
2 Work Entry work-entry.php Create work entries offline
3 Pending Pending entries page View queued entries
4 Error Error/offline notice page Show when network fails

3. METADATA STORED

Data Purpose
version Timestamp of data download
lastSyncTime When data was last synced
userContext userId, vendorId, projectId, dcId, role
stats Count of each data type downloaded

Auto-Download Trigger Points

When Auto-Download Occurs:

  1. On Login

    • User logs in successfully
    • Redirected to index.php
    • initOfflineSection() runs
    • autoDownloadOfflineData() triggers if no data or data is stale
  2. On Auto-Login

    • App opens with valid session/cookies
    • Same flow as manual login
    • index.php loads → auto-download triggers
  3. Manual Refresh

    • User clicks "Download Data" / "Refresh Data" button
    • Downloads latest data regardless of age

Auto-Download Conditions:

// Auto-download triggers when ALL conditions are met:
1. Running in WorkPro Android app (WorkProDevice is defined)
2. Device is online (navigator.onLine === true)
3. No offline data exists OR data is older than 24 hours

Android Storage

SQLite Tables (in workpro_offline.db):

Table Columns Index
vendors id, name -
projects id, name, vendor_id vendor_id
dcs id, name, vendor_id, project_id vendor_id, project_id
activities id, name, dc_id dc_id
schedules id, name, activity_id activity_id
feeders id, name, schedule_id schedule_id
items id, item_code, name, uom, feeder_id feeder_id
msps id, name, vendor_id, project_id vendor_id, project_id
pending_submissions id, form_data, created_at, status status

SharedPreferences (WorkProOfflineData):

Key Value
data_version Timestamp of last successful download
last_sync Milliseconds since epoch

File Storage (offline_pages/):

File Content
dashboard.html Cached dashboard page
work-entry.html Cached work entry form
pending.html Cached pending entries page
error.html Cached error page

JavaScript Functions

In index.php:

// Check and initialize offline section
initOfflineSection()

// Auto-download if no data exists
autoDownloadOfflineData()

// Silent background download (no UI)
downloadOfflineDataSilent()

// Manual download with progress UI
downloadOfflineData()

// Check and download offline HTML pages
checkAndDownloadOfflinePages()

Android Bridge (WorkProDevice):

// Store dropdown data
WorkProDevice.storeOfflineDropdowns(jsonData)

// Check if data exists
WorkProDevice.hasOfflineData()

// Get last sync time
WorkProDevice.getOfflineDataSyncTime()

// Download offline pages
WorkProDevice.downloadOfflinePages()

// Check if pages exist
WorkProDevice.hasOfflinePages()

API Response Format

/workpro/webview/api/dropdowns.php Response:

{
  "success": true,
  "version": 1735789200,
  "generatedAt": "2026-01-02 10:00:00",
  "userContext": {
    "userId": 123,
    "vendorId": 1,
    "projectId": 2,
    "dcId": 3,
    "role": "VENDOR"
  },
  "dropdowns": {
    "vendors": [{"id": 1, "name": "Vendor A"}],
    "projects": {"vendor_1": [{"id": 2, "name": "Project X"}]},
    "dcs": {"vendor_1_project_2": [{"id": 3, "name": "DC Alpha"}]},
    "activities": {"dc_3": [{"id": 10, "name": "Installation"}]},
    "schedules": {"activity_10": [{"id": 20, "name": "Phase 1"}]},
    "feeders": {"schedule_20": [{"id": 30, "name": "Feeder A"}]},
    "items": {"feeder_30": [{"id": 100, "boq_id": 100, "item_code": "ITM001", "name": "Cable", "uom": "m"}]},
    "msps": [{"id": 1, "name": "John Doe"}]
  },
  "stats": {
    "vendors": 1,
    "projects": 1,
    "dcs": 1,
    "activities": 5,
    "schedules": 10,
    "feeders": 25,
    "items": 150,
    "msps": 10,
    "totalRecords": 203
  }
}

Troubleshooting

Common Issues:

  1. "Download Data" fails with SQL error

    • Check if column names in query match database schema
    • Verify JOINs use correct table aliases
  2. MSPs not populating in offline mode

    • MSPs are stored as global (vendor_id=0, project_id=0)
    • getMSPsByVendorProject returns all MSPs regardless of filter
  3. Data not auto-downloading

    • Verify device is online
    • Check if WorkProDevice is defined (Android app only)
    • Check console for [AutoDownload] logs
  4. Stale data after 24 hours

    • Data auto-refreshes when older than 24 hours
    • User can manually refresh anytime

  • API: webview/api/dropdowns.php
  • API: webview/api/offline-pages.php
  • Frontend: webview/index.php (auto-download logic)
  • Frontend: webview/work-entry.php (uses offline data)
  • Android: app/.../OfflineDataManager.java
  • Android: app/.../OfflinePagesManager.java
  • Android: app/.../DeviceInfoInterface.java
  • JS Bridge: webview/js/android-bridge.js

Last Updated: January 2, 2026

workPro Documentation | v1.3
Login to Dashboard