Company Management

Table of contents

  1. Get Current Company Details
  2. Get Company Configuration
  3. Get Company Policy
  4. Get Company Modules
  5. Get Specific Module by Key
  6. Error Handling
  7. Session Context

The CompanyManager provides offline-first access to company/workspace data including basic details, configuration, policies, and modules.

Note: In Zuper terminology, "Company" represents the workspace concept (similar to Slack workspaces) that users belong to, not customer organizations.

Get Current Company Details

Get the basic company information for the current workspace:

when (val result = zync.companies.getCurrentCompanyDetail()) {
    is GetCompanyResult.Success -> {
        val company = result.data
        println("Company: ${company.companyName}")
        println("Currency: ${company.companyCurrency}")
        println("Timezone: ${company.companyTimezone}")
        println("Address: ${company.companyAddress}")
        println("Country: ${company.companyCountryCode}")
    }
    is GetCompanyResult.Failure -> {
        println("Error: ${result.error.message}")
        when (result.error) {
            is ZyncError.Network -> {
                println("Check your internet connection")
            }
            is ZyncError.Error -> {
                result.error.code?.let { code ->
                    println("Error code: $code")
                }
            }
        }
    }
}
if let zync.companies = zync.companies {
    let result = await zync.companies.getCurrentCompanyDetail()
    switch onEnum(of: result) {
    case .success(let success):
        let company = success.data
        print("Company: \(company.companyName)")
        print("Currency: \(company.companyCurrency ?? "N/A")")
        print("Timezone: \(company.companyTimezone ?? "N/A")")
        print("Address: \(company.companyAddress ?? "N/A")")
        print("Country: \(company.companyCountryCode ?? "N/A")")
    case .failure(let failure):
        print("Error: \(failure.error.message)")
        switch onEnum(of: failure.error) {
        case .network:
            print("Check your internet connection")
        case .error(let error):
            print("Error: \(error.message)")
            if let code = error.code {
                print("Error code: \(code)")
            }
        }
    }
}

Get Company Configuration

Access business settings and operational configurations:

when (val result = zync.companies.getCompanyConfig()) {
    is GetCompanyConfigResult.Success -> {
        val config = result.data
        // Business hours configuration
        val businessHours = config.businessHours
        if (businessHours != null) {
            println("Working hours: ${businessHours.startTime} - ${businessHours.endTime}")
            println("Working days: ${businessHours.workingDays}")
            println("Timezone: ${businessHours.timezone}")
        }
        
        // Job configuration
        val jobConfig = config.jobs
        if (jobConfig != null) {
            println("Auto assign job numbers: ${jobConfig.autoAssignJobNumber}")
            println("Allow edit after completion: ${jobConfig.allowJobEditAfterCompletion}")
        }
        
        // Timesheet configuration
        val timesheetConfig = config.timesheet
        if (timesheetConfig != null) {
            println("Timesheet enabled: ${timesheetConfig.enableTimesheet}")
            println("Require punch-in location: ${timesheetConfig.requirePunchInLocation}")
        }
        
        // General settings
        val general = config.general
        if (general != null) {
            println("Default currency: ${general.defaultCurrency}")
            println("Date format: ${general.dateFormat}")
            println("Time format: ${general.timeFormat}")
        }
    }
    is GetCompanyConfigResult.Failure -> {
        println("Error: ${result.error.message}")
        when (result.error) {
            is ZyncError.Network -> {
                println("Check your internet connection")
            }
            is ZyncError.Error -> {
                result.error.code?.let { code ->
                    println("Error code: $code")
                }
            }
        }
    }
}
if let zync.companies = zync.companies {
    let result = await zync.companies.getCompanyConfig()
    switch onEnum(of: result) {
    case .success(let success):
        let config = success.data
        // Business hours configuration
        if let businessHours = config.businessHours {
            print("Working hours: \(businessHours.startTime ?? "N/A") - \(businessHours.endTime ?? "N/A")")
            print("Working days: \(businessHours.workingDays ?? [])")
            print("Timezone: \(businessHours.timezone ?? "N/A")")
        }
        
        // Job configuration
        if let jobConfig = config.jobs {
            print("Auto assign job numbers: \(jobConfig.autoAssignJobNumber)")
            print("Allow edit after completion: \(jobConfig.allowJobEditAfterCompletion)")
        }
        
        // Timesheet configuration
        if let timesheetConfig = config.timesheet {
            print("Timesheet enabled: \(timesheetConfig.enableTimesheet)")
            print("Require punch-in location: \(timesheetConfig.requirePunchInLocation)")
        }
        
        // General settings
        if let general = config.general {
            print("Default currency: \(general.defaultCurrency ?? "N/A")")
            print("Date format: \(general.dateFormat ?? "N/A")")
            print("Time format: \(general.timeFormat ?? "N/A")")
        }
    case .failure(let failure):
        print("Error: \(failure.error.message)")
        switch onEnum(of: failure.error) {
        case .network:
            print("Check your internet connection")
        case .error(let error):
            print("Error: \(error.message)")
            if let code = error.code {
                print("Error code: \(code)")
            }
        }
    }
}

Get Company Policy

Access feature flags and security policies:

when (val result = zync.companies.getCompanyPolicy()) {
    is GetCompanyPolicyResult.Success -> {
        val policy = result.data
        // Security settings
        println("SSO enabled: ${policy.ssoEnabled}")
        println("2FA enabled: ${policy.twoFactorEnabled}")
        println("Offline mode enabled: ${policy.offlineEnabled}")
        
        // Feature flags
        println("Service tasks enabled: ${policy.serviceTaskEnabled}")
        println("Financing enabled: ${policy.financingEnabled}")
        println("Customer portal enabled: ${policy.customerPortalEnabled}")
        println("Expense tracking enabled: ${policy.expenseTrackingEnabled}")
        
        // Attachment policy
        val attachmentPolicy = policy.attachmentsPolicy
        if (attachmentPolicy != null) {
            println("Compress images: ${attachmentPolicy.compressImage}")
            println("Max attachment size: ${attachmentPolicy.maxAttachmentSize}MB")
            println("Max attachments: ${attachmentPolicy.maxNoOfAttachments}")
        }
        
        // ZuperPay settings
        val zuperPay = policy.zuperPayPolicy
        if (zuperPay != null) {
            println("ZuperPay enabled: ${zuperPay.isEnabled}")
            println("Tap to pay enabled: ${zuperPay.isTapToPayEnabled}")
        }
    }
    is GetCompanyPolicyResult.Failure -> {
        println("Error: ${result.error.message}")
        when (result.error) {
            is ZyncError.Network -> {
                println("Check your internet connection")
            }
            is ZyncError.Error -> {
                result.error.code?.let { code ->
                    println("Error code: $code")
                }
            }
        }
    }
}
if let zync.companies = zync.companies {
    let result = await zync.companies.getCompanyPolicy()
    switch onEnum(of: result) {
    case .success(let success):
        let policy = success.data
        // Security settings
        print("SSO enabled: \(policy.ssoEnabled)")
        print("2FA enabled: \(policy.twoFactorEnabled)")
        print("Offline mode enabled: \(policy.offlineEnabled)")
        
        // Feature flags
        print("Service tasks enabled: \(policy.serviceTaskEnabled)")
        print("Financing enabled: \(policy.financingEnabled)")
        print("Customer portal enabled: \(policy.customerPortalEnabled)")
        print("Expense tracking enabled: \(policy.expenseTrackingEnabled)")
        
        // Attachment policy
        if let attachmentPolicy = policy.attachmentsPolicy {
            print("Compress images: \(attachmentPolicy.compressImage)")
            print("Max attachment size: \(attachmentPolicy.maxAttachmentSize)MB")
            print("Max attachments: \(attachmentPolicy.maxNoOfAttachments)")
        }
        
        // ZuperPay settings
        if let zuperPay = policy.zuperPayPolicy {
            print("ZuperPay enabled: \(zuperPay.isEnabled)")
            print("Tap to pay enabled: \(zuperPay.isTapToPayEnabled)")
        }
    case .failure(let failure):
        print("Error: \(failure.error.message)")
        switch onEnum(of: failure.error) {
        case .network:
            print("Check your internet connection")
        case .error(let error):
            print("Error: \(error.message)")
            if let code = error.code {
                print("Error code: \(code)")
            }
        }
    }
}

Get Company Modules

Access available modules/features for the company:

when (val result = zync.companies.getCompanyModules()) {
    is GetCompanyModulesResult.Success -> {
        val modules = result.data
        println("Available modules: ${modules.size}")
        
        modules.forEach { module ->
            println("Module: ${module.moduleName} (${module.moduleKey})")
            println("  UID: ${module.moduleUid}")
        }
    }
    is GetCompanyModulesResult.Failure -> {
        println("Error: ${result.error.message}")
        when (result.error) {
            is ZyncError.Network -> {
                println("Check your internet connection")
            }
            is ZyncError.Error -> {
                result.error.code?.let { code ->
                    println("Error code: $code")
                }
            }
        }
    }
}
if let zync.companies = zync.companies {
    let result = await zync.companies.getCompanyModules()
    switch onEnum(of: result) {
    case .success(let success):
        let modules = success.data
        print("Available modules: \(modules.count)")
        
        for module in modules {
            print("Module: \(module.moduleName) (\(module.moduleKey))")
            print("  UID: \(module.moduleUid)")
        }
    case .failure(let failure):
        print("Error: \(failure.error.message)")
        switch onEnum(of: failure.error) {
        case .network:
            print("Check your internet connection")
        case .error(let error):
            print("Error: \(error.message)")
            if let code = error.code {
                print("Error code: \(code)")
            }
        }
    }
}

Get Specific Module by Key

Check if a specific module is available:

when (val result = zync.companies.getCompanyModuleByKey("time_sheet")) {
    is GetCompanyModuleResult.Success -> {
        val timeSheetModule = result.data
        println("Time sheet module is available: ${timeSheetModule.moduleName}")
    }
    is GetCompanyModuleResult.Failure -> {
        println("Time sheet module not available for this company")
        when (result.error) {
            is ZyncError.Network -> {
                println("Check your internet connection")
            }
            is ZyncError.Error -> {
                result.error.code?.let { code ->
                    println("Error code: $code")
                }
            }
        }
    }
}

// Check for other common modules
val invoiceResult = zync.companies.getCompanyModuleByKey("invoice")
val quoteResult = zync.companies.getCompanyModuleByKey("quote") 
val assetResult = zync.companies.getCompanyModuleByKey("asset")
if let zync.companies = zync.companies {
    let result = await zync.companies.getCompanyModuleByKey(moduleKey: "time_sheet")
    switch onEnum(of: result) {
    case .success(let success):
        let timeSheetModule = success.data
        print("Time sheet module is available: \(timeSheetModule.moduleName)")
    case .failure(let failure):
        print("Time sheet module not available for this company")
        switch onEnum(of: failure.error) {
        case .network:
            print("Check your internet connection")
        case .error(let error):
            print("Error: \(error.message)")
            if let code = error.code {
                print("Error code: \(code)")
            }
        }
    }
    
    // Check for other common modules
    let invoiceResult = await zync.companies.getCompanyModuleByKey(moduleKey: "invoice")
    let quoteResult = await zync.companies.getCompanyModuleByKey(moduleKey: "quote")
    let assetResult = await zync.companies.getCompanyModuleByKey(moduleKey: "asset")
}

Error Handling

All CompanyManager methods return result types with proper success/failure handling:

// Proper result handling pattern
when (val result = zync.companies.getCurrentCompanyDetail()) {
    is GetCompanyResult.Success -> {
        val company = result.data
        // Use company data safely
        processCompanyData(company)
    }
    is GetCompanyResult.Failure -> {
        println("Company data not available: ${result.error.message}")
        when (result.error) {
            is ZyncError.Network -> {
                println("Check your internet connection")
            }
            is ZyncError.Error -> {
                result.error.code?.let { code ->
                    println("Error code: $code")
                    if (code == "NO_SESSION") {
                        // Handle session error
                    }
                }
            }
        }
        return
    }
}

// Check for specific configuration
when (val policyResult = zync.companies.getCompanyPolicy()) {
    is GetCompanyPolicyResult.Success -> {
        val policy = policyResult.data
        if (!policy.offlineEnabled) {
            println("Offline mode not enabled for this company")
        }
    }
    is GetCompanyPolicyResult.Failure -> {
        println("Could not load company policy: ${policyResult.error.message}")
    }
}
// Proper result handling pattern
if let zync.companies = zync.companies {
    let result = await zync.companies.getCurrentCompanyDetail()
    switch onEnum(of: result) {
    case .success(let success):
        let company = success.data
        // Use company data safely
        processCompanyData(company)
    case .failure(let failure):
        print("Company data not available: \(failure.error.message)")
        switch onEnum(of: failure.error) {
        case .network:
            print("Check your internet connection")
        case .error(let error):
            print("Error: \(error.message)")
            if let code = error.code {
                print("Error code: \(code)")
                if code == "NO_SESSION" {
                    // Handle session error
                }
            }
        }
        return
    }
    
    // Check for specific configuration
    let policyResult = await zync.companies.getCompanyPolicy()
    switch onEnum(of: policyResult) {
    case .success(let success):
        let policy = success.data
        if !policy.offlineEnabled {
            print("Offline mode not enabled for this company")
        }
    case .failure(let failure):
        print("Could not load company policy: \(failure.error.message)")
    }
}

Session Context

All CompanyManager methods are session-aware:

  • All methods automatically use the current session’s company UID
  • No need to manually pass company identifiers
  • Returns null or empty results if no valid session exists

This ensures that company operations are always performed in the correct workspace context.


Copyright © 2025 Zuper Inc. All rights reserved. This software is proprietary and confidential.