/**
    @todo Should be Part of WorkOrder Class
*/
function wo2iv($id)
{
    $wo = new WorkOrder($id);
    try {
        $iv = $wo->toInvoice();
    } catch (Exception $e) {
        echo "EE " . $e . "\n";
        return false;
    }
    echo "WO #{$wo->id} => IV #{$iv->id} for {${$iv->bill_amount}}\n";
    // Post to their Account
    $C = new Contact($iv->contact_id);
    // Generate a Transaction to Post to This Clients Account Receivable
    $aje = new AccountJournalEntry();
    $aje->date = $iv->date;
    $aje->note = 'Charge for Invoice #' . $iv->id;
    $aje->save();
    // Debit Accounts Receivable for this Client
    $ale = new AccountLedgerEntry();
    $ale->account_id = $_ENV['account']['receive_account_id'];
    $ale->account_journal_id = $aje->id;
    $ale->amount = abs($iv->bill_amount) * -1;
    $ale->link_to = ImperiumBase::getObjectType('contact');
    $ale->link_id = $iv->contact_id;
    $ale->save();
    // Credit Customer Account - or Revenue for Instant Revenue?
    // Old Query, Why from account by contact?
    $ale = new AccountLedgerEntry();
    if ($C->account_id) {
        $ale->account_id = $C->account_id;
    } else {
        $ale->account_id = $_ENV['account']['revenue_account_id'];
    }
    $ale->account_journal_id = $aje->id;
    $ale->amount = abs($iv->bill_amount);
    $ale->link_to = ImperiumBase::getObjectType($iv);
    $ale->link_id = $iv->id;
    $ale->save();
    echo "IV Posted {$aje->note} " . number_format($ale->amount, 2) . "\n";
    // Send The Invoice via Email
    return $iv;
}