Create a mobile (android/ios)and web app for educational consultancy having these It a sophisticated, multi-tenant enterprise resource planning (ERP) system designed for educational consultancies. It provides a unified platform for managing the entire student admission lifecycle, from lead generation to final enrollment and financial reconciliation. The system features role-based access for internal staff (Admins, Managers, Team Leaders, Sales Staff) and external agents, ensuring data security and process integrity. Key functionalities include advanced financial ledgers, multi-pipeline workflow management, collaborative workspaces, custom data management via worksheets, and intelligent automation through a Telegram bot and AI-powered analytics. 2. Core Data Models & Entities The system is built upon a rich set of interconnected data models: * Users & Agents: * User: Represents internal staff with specific roles (Admin, Manager, TeamLeader, SalesStaff). Each role is tied to a granular PermissionSet. Users have sales targets, commission rates (uniform or special), and optional login access with IP restrictions. * Agent: Represents external partners who generate leads. They are assigned to a staff member and also have configurable commission rates. They have a separate, simplified login portal. * Academics & Workflow: * Workflow: Defines a high-level admission process pipeline (e.g., "General Admissions"). * PipelineStage: Represents a specific step within a Workflow (e.g., "Document Verification," "Offer Letter"). Each stage has a defined order. * UniversityCollege: Represents an academic institution, linked to a specific Workflow. * Course: A specific academic program offered by a UniversityCollege, with defined sessions, a uniform sales rate, and an optional purchase rate. * Admissions Lifecycle: * Lead: The initial entry point for a prospective student, with a status lifecycle (New, Contacted, Qualified, Unqualified, Converted). Leads can be scored by an AI for potential. * Admission: The central record for a student's application. It tracks the student's details, selected course, assigned staff/agent, total fees, and follows a detailed status lifecycle (from Pending Approval to Accepted or CancellationApproved). * SubmittedDocument: Digital records of required documents for an admission, each with a verification status. * Financial Entities: * Payment: A record of a fee payment made by a student for an admission, with a status (Pending, Approved, Rejected) and proof. * WalletTransaction: Manages an agent's prepaid wallet, tracking Recharge, Payment, and Refund transactions. * CommissionEntry: Records a commission amount earned by a staff member or agent from a specific admission. * StaffLedgerEntry & AgentLedgerEntry: A double-entry accounting ledger for each staff member and agent, tracking credits (commissions earned) and debits (payouts). * Payout: A record of a payment made to a staff member or agent from their commission balance. * Expense: A record of general business expenses (e.g., Salary, Office, Marketing). * Purchase: A batch record that groups multiple admissions to be "purchased" from a Vendor (e.g., a university), tracking the cost of sales. * Refund: A record of money returned to a student after a cancellation is approved. * Productivity & Collaboration: * Task: A process-driven task linked to an Admission and a PipelineStage. * CustomTask: A general, ad-hoc task assigned between users. * Workspace: A collaborative project space with a Kanban board, document sharing, and a dedicated chat for team coordination. * Worksheet: A highly flexible, user-creatable spreadsheet-like module for managing custom data sets with customizable columns and conditional formatting rules. 3. Application Modules & Logic The application is divided into distinct modules, each governed by the permission system. * Dashboard: Provides an at-a-glance view of key metrics. It compares individual and company-wide sales performance against set targets (weekly/monthly). It also features a visual lead funnel and a feed of recent activities (new admissions, approved payments). * Admissions & Workflow: * Logic: Admissions can only be edited by authorized users based on their role's view scope (own, team, all) or if they have an approved EditRequest. * Workflow (/workflow): An admin-only Kanban-style view where admissions are visualized as cards in columns representing pipeline stages. Admins can drag-and-drop an admission card from the "Backlog" to a new stage to create and assign a new Task. * Tasks (/pipeline-tasks): Users manage tasks assigned to them. They can update status, upload proof, and communicate via a task-specific chat with followers. Task completion requires manager/admin approval. * Lead Management (/leads): * Logic: Leads are displayed in a Kanban board organized by status. Users can drag-and-drop leads to update their status. * AI Scoring: An "AI Score Leads" feature uses the Gemini API to analyze unscored leads' course interest and notes, assigning a potential score (1-100) and a justification to help prioritize follow-ups. * Conversion: A qualified lead can be converted into a formal Admission, carrying over key details and updating the lead's status to Converted. * Financial Management: * Approvals (/approvals): A central hub for managers and admins to approve or reject pending admissions, payments, wallet recharges, and cancellation requests. * Commissions (/commissions): Admins can record commission splits for an admission, which automatically creates credit entries in the respective staff/agent ledgers. They can also record payouts, which create debit entries. * Purchases (/purchases): Admins can group approved admissions into a Purchase batch to calculate the total cost of sales owed to a specific vendor (university). Payments made against this purchase are tracked separately. * Reports (/reports): A powerful module featuring: * P&L Statement: Automatically calculates total revenue, cost of sales, gross profit, operating expenses, and net profit. Access to sensitive data like cost of sales is restricted to Admins. * Custom Report Builder: A flexible tool to build and export detailed reports on admissions data with custom columns, filters, and grouping/aggregation. * AI Financial Analyst: Uses the Gemini API to analyze the P&L data for a selected date range and generates a human-like summary with key insights and actionable recommendations. * User & Agent Management: * Users (/users): Admins/Managers can create and manage staff, define their roles, targets, and salaries, and configure permissions. The permission system is hierarchical and highly granular, controlling view, edit, and delete rights for every module. * Agents (/agents): Staff can manage their assigned agents. Admins can oversee all agents and manage their login credentials and commission structures. * Masters (/masters): * Logic: This is the system's configuration hub, accessible only to high-level users. It enforces data integrity; for example, a university cannot be deleted if it has courses linked to it. * Features: Admins manage all core data: Universities, Courses (with their sessions), Workflows, Pipeline Stages, Document Types, Vendors, Custom Fields for admissions, and create entirely new Custom Modules. 4. Core Business Rules & Automation * Role-Based Access Control (RBAC): Every action is governed by the hasPermission logic. * view: 'own' restricts a user to records they created/are assigned. * view: 'team' expands access to include records of their team members (for Team Leaders). * view: 'all' provides full visibility. * edit and delete are simple boolean flags. * Approval Flows: 1. A Sales Staff member creates an admission, which enters Pending Approval status and generates a notification for managers. 2. A manager approves it, setting required documents and moving it to Documents Pending. 3. A payment is added, entering Pending status until approved by a manager. 4. A user requests cancellation, which enters Cancellation Requested status and requires an admin with a master password to approve and process refunds. * Telegram Bot Integration: * Users can link their Telegram accounts to receive real-time notifications for critical events (e.g., "New Task Assigned," "Payment Approved"). * The bot's messages, commands, and notification triggers are fully customizable by an Admin in the Bot settings module. * Data Integrity & Security: * Login logic includes brute-force protection (account lockout after 5 failed attempts) and optional IP address restriction for users. * The system prevents the deletion of master data that is actively in use (e.g., deleting a vendor linked to a purchase). * All financial transactions are logged in immutable ledgers for a clear audit trail.