Add company management module with registration and entity switching
This commit is contained in:
		
							
								
								
									
										173
									
								
								actix_mvc_app/static/js/company.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										173
									
								
								actix_mvc_app/static/js/company.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,173 @@
 | 
			
		||||
// Company data (would be loaded from backend in production)
 | 
			
		||||
var companyData = {
 | 
			
		||||
    'company1': {
 | 
			
		||||
        name: 'Zanzibar Digital Solutions',
 | 
			
		||||
        type: 'Startup FZC',
 | 
			
		||||
        status: 'Active',
 | 
			
		||||
        registrationDate: '2025-04-01',
 | 
			
		||||
        purpose: 'Digital solutions and blockchain development',
 | 
			
		||||
        plan: 'Startup FZC - $50/month',
 | 
			
		||||
        nextBilling: '2025-06-01',
 | 
			
		||||
        paymentMethod: 'Credit Card (****4582)',
 | 
			
		||||
        shareholders: [
 | 
			
		||||
            { name: 'John Smith', percentage: '60%' },
 | 
			
		||||
            { name: 'Sarah Johnson', percentage: '40%' }
 | 
			
		||||
        ],
 | 
			
		||||
        contracts: [
 | 
			
		||||
            { name: 'Articles of Incorporation', status: 'Signed' },
 | 
			
		||||
            { name: 'Terms & Conditions', status: 'Signed' },
 | 
			
		||||
            { name: 'Digital Asset Issuance', status: 'Signed' }
 | 
			
		||||
        ]
 | 
			
		||||
    },
 | 
			
		||||
    'company2': {
 | 
			
		||||
        name: 'Blockchain Innovations Ltd',
 | 
			
		||||
        type: 'Growth FZC',
 | 
			
		||||
        status: 'Active',
 | 
			
		||||
        registrationDate: '2025-03-15',
 | 
			
		||||
        purpose: 'Blockchain technology research and development',
 | 
			
		||||
        plan: 'Growth FZC - $100/month',
 | 
			
		||||
        nextBilling: '2025-06-15',
 | 
			
		||||
        paymentMethod: 'Bank Transfer',
 | 
			
		||||
        shareholders: [
 | 
			
		||||
            { name: 'Michael Chen', percentage: '35%' },
 | 
			
		||||
            { name: 'Aisha Patel', percentage: '35%' },
 | 
			
		||||
            { name: 'David Okonkwo', percentage: '30%' }
 | 
			
		||||
        ],
 | 
			
		||||
        contracts: [
 | 
			
		||||
            { name: 'Articles of Incorporation', status: 'Signed' },
 | 
			
		||||
            { name: 'Terms & Conditions', status: 'Signed' },
 | 
			
		||||
            { name: 'Digital Asset Issuance', status: 'Signed' },
 | 
			
		||||
            { name: 'Physical Asset Holding', status: 'Signed' }
 | 
			
		||||
        ]
 | 
			
		||||
    },
 | 
			
		||||
    'company3': {
 | 
			
		||||
        name: 'Sustainable Energy Cooperative',
 | 
			
		||||
        type: 'Cooperative FZC',
 | 
			
		||||
        status: 'Pending',
 | 
			
		||||
        registrationDate: '2025-05-01',
 | 
			
		||||
        purpose: 'Renewable energy production and distribution',
 | 
			
		||||
        plan: 'Cooperative FZC - $200/month',
 | 
			
		||||
        nextBilling: 'Pending Activation',
 | 
			
		||||
        paymentMethod: 'Pending',
 | 
			
		||||
        shareholders: [
 | 
			
		||||
            { name: 'Community Energy Group', percentage: '40%' },
 | 
			
		||||
            { name: 'Green Future Initiative', percentage: '30%' },
 | 
			
		||||
            { name: 'Sustainable Living Collective', percentage: '30%' }
 | 
			
		||||
        ],
 | 
			
		||||
        contracts: [
 | 
			
		||||
            { name: 'Articles of Incorporation', status: 'Signed' },
 | 
			
		||||
            { name: 'Terms & Conditions', status: 'Signed' },
 | 
			
		||||
            { name: 'Cooperative Governance', status: 'Pending' }
 | 
			
		||||
        ]
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// Current company ID for modal
 | 
			
		||||
var currentCompanyId = null;
 | 
			
		||||
 | 
			
		||||
// View company details function
 | 
			
		||||
function viewCompanyDetails(companyId) {
 | 
			
		||||
    // Store current company ID
 | 
			
		||||
    currentCompanyId = companyId;
 | 
			
		||||
    
 | 
			
		||||
    // Get company data
 | 
			
		||||
    const company = companyData[companyId];
 | 
			
		||||
    if (!company) return;
 | 
			
		||||
    
 | 
			
		||||
    // Update modal title
 | 
			
		||||
    document.getElementById('companyDetailsModalLabel').innerHTML = 
 | 
			
		||||
        `<i class="bi bi-building me-2"></i>${company.name} Details`;
 | 
			
		||||
    
 | 
			
		||||
    // Update general information
 | 
			
		||||
    document.getElementById('modal-company-name').textContent = company.name;
 | 
			
		||||
    document.getElementById('modal-company-type').textContent = company.type;
 | 
			
		||||
    document.getElementById('modal-registration-date').textContent = company.registrationDate;
 | 
			
		||||
    
 | 
			
		||||
    // Update status with appropriate badge
 | 
			
		||||
    const statusBadge = company.status === 'Active' ? 
 | 
			
		||||
        `<span class="badge bg-success">${company.status}</span>` : 
 | 
			
		||||
        `<span class="badge bg-warning text-dark">${company.status}</span>`;
 | 
			
		||||
    document.getElementById('modal-status').innerHTML = statusBadge;
 | 
			
		||||
    
 | 
			
		||||
    document.getElementById('modal-purpose').textContent = company.purpose;
 | 
			
		||||
    
 | 
			
		||||
    // Update billing information
 | 
			
		||||
    document.getElementById('modal-plan').textContent = company.plan;
 | 
			
		||||
    document.getElementById('modal-next-billing').textContent = company.nextBilling;
 | 
			
		||||
    document.getElementById('modal-payment-method').textContent = company.paymentMethod;
 | 
			
		||||
    
 | 
			
		||||
    // Update shareholders table
 | 
			
		||||
    const shareholdersTable = document.getElementById('modal-shareholders');
 | 
			
		||||
    shareholdersTable.innerHTML = '';
 | 
			
		||||
    company.shareholders.forEach(shareholder => {
 | 
			
		||||
        const row = document.createElement('tr');
 | 
			
		||||
        row.innerHTML = `
 | 
			
		||||
            <td>${shareholder.name}</td>
 | 
			
		||||
            <td>${shareholder.percentage}</td>
 | 
			
		||||
        `;
 | 
			
		||||
        shareholdersTable.appendChild(row);
 | 
			
		||||
    });
 | 
			
		||||
    
 | 
			
		||||
    // Update contracts table
 | 
			
		||||
    const contractsTable = document.getElementById('modal-contracts');
 | 
			
		||||
    contractsTable.innerHTML = '';
 | 
			
		||||
    company.contracts.forEach(contract => {
 | 
			
		||||
        const row = document.createElement('tr');
 | 
			
		||||
        const statusBadge = contract.status === 'Signed' ? 
 | 
			
		||||
            `<span class="badge bg-success">${contract.status}</span>` : 
 | 
			
		||||
            `<span class="badge bg-warning text-dark">${contract.status}</span>`;
 | 
			
		||||
        
 | 
			
		||||
        row.innerHTML = `
 | 
			
		||||
            <td>${contract.name}</td>
 | 
			
		||||
            <td>${statusBadge}</td>
 | 
			
		||||
            <td><button class="btn btn-sm btn-outline-primary" onclick="viewContract('${contract.name.toLowerCase().replace(/\s+/g, '-')}')">View</button></td>
 | 
			
		||||
        `;
 | 
			
		||||
        contractsTable.appendChild(row);
 | 
			
		||||
    });
 | 
			
		||||
    
 | 
			
		||||
    // Show the modal
 | 
			
		||||
    const modal = new bootstrap.Modal(document.getElementById('companyDetailsModal'));
 | 
			
		||||
    modal.show();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Switch to entity function
 | 
			
		||||
function switchToEntity(companyId) {
 | 
			
		||||
    const company = companyData[companyId];
 | 
			
		||||
    if (!company) return;
 | 
			
		||||
    
 | 
			
		||||
    // In a real application, this would redirect to the entity context
 | 
			
		||||
    // For now, we'll just show an alert
 | 
			
		||||
    alert(`Switching to ${company.name} entity context. All UI will now reflect this entity's governance, billing, and other features.`);
 | 
			
		||||
    
 | 
			
		||||
    // This would typically involve:  
 | 
			
		||||
    // 1. Setting a session/cookie for the current entity
 | 
			
		||||
    // 2. Redirecting to the dashboard with that entity context
 | 
			
		||||
    // window.location.href = `/dashboard?entity=${companyId}`;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Switch to entity from modal
 | 
			
		||||
function switchToEntityFromModal() {
 | 
			
		||||
    if (currentCompanyId) {
 | 
			
		||||
        switchToEntity(currentCompanyId);
 | 
			
		||||
        // Close the modal
 | 
			
		||||
        const modal = bootstrap.Modal.getInstance(document.getElementById('companyDetailsModal'));
 | 
			
		||||
        modal.hide();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// View contract function
 | 
			
		||||
function viewContract(contractId) {
 | 
			
		||||
    // In a real application, this would open the contract document
 | 
			
		||||
    // For now, we'll just show an alert
 | 
			
		||||
    alert(`Viewing contract: ${contractId.replace(/-/g, ' ')}`);
 | 
			
		||||
    
 | 
			
		||||
    // This would typically involve:  
 | 
			
		||||
    // 1. Fetching the contract document from the server
 | 
			
		||||
    // 2. Opening it in a viewer or new tab
 | 
			
		||||
    // window.open(`/contracts/view/${contractId}`, '_blank');
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Initialize when DOM is loaded
 | 
			
		||||
document.addEventListener('DOMContentLoaded', function() {
 | 
			
		||||
    console.log('Company management script loaded');
 | 
			
		||||
});
 | 
			
		||||
@@ -411,18 +411,9 @@ document.addEventListener('DOMContentLoaded', function() {
 | 
			
		||||
            if (liquidationUnitElement) liquidationUnitElement.textContent = assetUnit;
 | 
			
		||||
            
 | 
			
		||||
            // Calculate collateral value
 | 
			
		||||
            const amount = parseFloat(collateralAmountInput.value) || 0;
 | 
			
		||||
            let collateralValue = 0;
 | 
			
		||||
            
 | 
			
		||||
            if (assetType === 'token') {
 | 
			
		||||
                // For tokens, calculate based on token price
 | 
			
		||||
                const tokenPrice = assetValue / assetAmount;
 | 
			
		||||
                collateralValue = amount * tokenPrice;
 | 
			
		||||
            } else {
 | 
			
		||||
                // For NFTs and other assets, use the full value if amount is 1
 | 
			
		||||
                collateralValue = amount === 1 ? assetValue : 0;
 | 
			
		||||
                liquidationPriceElement.value = (borrowedValue * 1.2).toFixed(2);
 | 
			
		||||
            }
 | 
			
		||||
            
 | 
			
		||||
            if (collateralValueElement) collateralValueElement.value = collateralValue.toFixed(2);
 | 
			
		||||
            
 | 
			
		||||
            // Calculate max loan amount (75% of collateral value)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user