MasterControl

Master Account Control

Manage snapshots and sync changes to all cloned instances

Master Account Sale Calculation Codes

Read-only reference. Click the copy button on each snippet to copy it to your clipboard.

Team Sales Code
Step 1 — Get Report Start Date
const getReportStartForAccount = (subaccountId) => {
  const now = new Date();
  const mStart = new Date(now.getFullYear(), now.getMonth(), 1);
  const finalized = allReportConfigs.filter(
    c => c.subaccount_id === subaccountId && c.is_finalized
  );
  if (finalized.length > 0) {
    const sorted = [...finalized].sort(
      (a, b) => new Date(b.cutoff_date) - new Date(a.cutoff_date)
    );
    const lastCutoff = new Date(sorted[0].cutoff_date);
    return new Date(lastCutoff.getTime() + 86400000);
  }
  return mStart;
};
Step 2 — Filter Owner's Sold Vouchers
const getSoldVouchers = (accountId) => {
  const startNorm = new Date(getReportStartForAccount(accountId));
  startNorm.setHours(0, 0, 0, 0);
  return vouchers.filter(v => {
    if (v.created_by_subaccount_id !== accountId) return false;
    if (v.status !== 'active') return false;
    if (!v.activation_date) return false;
    return new Date(v.activation_date) >= startNorm;
  });
};
Step 3 — Calculate Owner Sales / Commission / Net
const calculateStats = (accountId, commissionRateOverride) => {
  const sales = getSoldVouchers(accountId);
  const totalSales = sales.reduce(
    (sum, v) => sum + (v.sale_price || v.price || 0), 0
  );
  let account = subResellers.find(s => s.id === accountId);
  if (!account && accountId === ownerData?.id) account = ownerData;
  const rate = commissionRateOverride !== undefined
    ? commissionRateOverride
    : (account?.commission_rate || 0);
  const commission = totalSales * (rate / 100);
  const netSales = totalSales - commission;
  return { salesCount: sales.length, totalSales, commission, netSales };
};
Step 4 — Owner Stats Final Call
const ownerStats = calculateStats(ownerData?.id);

Batch Activate Paid Clients

Activate all clients who have completed payments but routers aren't synced yet

🔗 Fix: Reassign Vouchers to ALTO LAS MESAS

Finds all 1000 vouchers belonging to ALTO LAS MESAS (by name) and links them correctly to their SubAccount ID so their dashboard shows the data.

Client Network Status
0 Online
0 Offline

No ping data yet. Click "Ping All Now" to start monitoring.

No Snapshot Yet

Click "Capture Snapshot" to freeze the current Master Account state.

Billing & Client Management

Generate Invoices

Create invoices for all clients with upcoming due dates

Sync to Clones

Active Clones: 0

No active clones to sync to.

💡 Tip: Click the button above to push the latest changes from this master app to all cloned business instances.

Sync Individual Business Clones

How Sync Works

When you make improvements to this app, use this section to push the same updates to individual business clones. Each business keeps their own private data — only the app code/structure is synced.

Sync to All Clones

Push all latest improvements to every business clone at once.

Business Clones
No businesses with active clones found. Create a business first via Business Management.
Report Formulas Backup & Restore

Backup your current report formulas and configuration. If something breaks, restore from here in seconds instead of rebuilding everything.