#!/usr/bin/env python3 """Interactive command-line runner for transfer calculations.""" from contract import Contract from transfer import Transfer from decimal import Decimal def get_contract_input(contract_label: str, is_source: bool = True) -> Contract: """Get contract details from user input.""" print(f"\n--- {contract_label} ---") contract_id = input(f"{contract_label} ID: ").strip() name_input = input(f"{contract_label} Name (optional): ").strip() name = name_input if name_input else f"Contract {contract_id}" balance_str = input(f"{contract_label} Closing Balance: ").strip() balance = float(balance_str) if balance_str else 0.0 net_revenue = None gross_revenue = None is_recouped = False if is_source: print(f"\n{contract_label} Revenue (for percentage calculations):") net_rev_str = input(f" Net Revenue (press Enter to use closing balance): ").strip() net_revenue = float(net_rev_str) if net_rev_str else None gross_rev_str = input(f" Gross Revenue (press Enter to use closing balance): ").strip() gross_revenue = float(gross_rev_str) if gross_rev_str else None recouped_str = input(f"{contract_label} Recouped? (y/n, default n): ").strip().lower() is_recouped = recouped_str == 'y' return Contract( contract_id=contract_id, name=name, projected_balance=balance, net_revenue=net_revenue, gross_revenue=gross_revenue, is_recouped=is_recouped ) def get_transfer_type() -> str: """Get transfer type from user.""" print("\n--- Transfer Type ---") print("1. Percentage Revenue (% of net or gross revenue)") print("2. Percentage Balance (% of closing balance)") print("3. Fixed Amount (perpetual fixed amount)") print("4. All Recouped (all earnings if recouped)") choice = input("\nSelect transfer type (1-4): ").strip() type_map = { "1": "percentage_revenue", "2": "percentage_balance", "3": "fixed_amount", "4": "all_recouped" } return type_map.get(choice, "percentage_revenue") def get_calculation_params(transfer_type: str) -> dict: """Get calculation parameters based on transfer type.""" params = {} if transfer_type == "percentage_revenue": percentage = float(input("Percentage (e.g., 50 for 50%): ").strip()) base = input("Base (net_revenue or gross_revenue, default net_revenue): ").strip() params = { "percentage": percentage, "base": base if base else "net_revenue" } elif transfer_type == "percentage_balance": percentage = float(input("Percentage (e.g., 85 for 85%): ").strip()) params = {"percentage": percentage} elif transfer_type == "fixed_amount": amount = float(input("Fixed amount: ").strip()) params = {"amount": amount} elif transfer_type == "all_recouped": base = input("Base (net_revenue or gross_revenue, default net_revenue): ").strip() params = {"base": base if base else "net_revenue"} return params def main(): print("=" * 80) print("TRANSFER OF EARNINGS CALCULATOR") print("=" * 80) contract_a = get_contract_input("Contract A (FROM)", is_source=True) contract_b = get_contract_input("Contract B (TO)", is_source=False) transfer_type = get_transfer_type() print("\n--- Calculation Parameters ---") calc_params = get_calculation_params(transfer_type) transfer = Transfer( transfer_id="T001", from_contract_id=contract_a.contract_id, to_contract_id=contract_b.contract_id, calculation_type=transfer_type, calculation_params=calc_params ) amount = transfer.calculate_amount(contract_a) print("\n" + "=" * 80) print("RESULTS") print("=" * 80) print(f"\nFrom: {contract_a}") print(f"To: {contract_b}") print(f"\nTransfer: {transfer}") print(f"Calculation Params: {calc_params}") print(f"\n{'='*80}") print(f"TRANSFER AMOUNT: ${amount:,.2f}") print(f"{'='*80}") print(f"\nAfter Transfer:") print(f" Contract A Balance: ${contract_a.projected_balance:,.2f} → ${contract_a.projected_balance - float(amount):,.2f}") print(f" Contract B Balance: ${contract_b.projected_balance:,.2f} → ${contract_b.projected_balance + float(amount):,.2f}") if __name__ == "__main__": try: main() except KeyboardInterrupt: print("\n\nCalculation cancelled.") except Exception as e: print(f"\nError: {e}")