/** * Send emails to any members with a positive balance. */ function command_amazon_payment_email() { global $config_email_from; global $config_site_title; // Get balances and contacts $cids = payment_contact_filter(array('balance_due' => true)); $balances = payment_accounts(array('cid' => $cids)); $contacts = crm_get_data('contact', array('cid' => $cids)); $cidToContact = crm_map($contacts, 'cid'); // Email each contact with a balance foreach ($balances as $cid => $balance) { // Construct button $params = array('referenceId' => $cid, 'amount' => $balance['code'] . ' ' . payment_format_currency($balance, false), 'description' => 'CRM Dues Payment'); $amount = payment_format_currency($balance); $button = theme('amazon_payment_button', $cid, $params); // Send email $to = $cidToContact[$cid]['email']; $subject = "[{$config_site_title}] Payment Due"; $from = $config_email_from; $headers = "Content-type: text/html\r\nFrom: {$from}\r\n"; $message = "<p>Hello,<br/>Your current account balance is {$amount}. To pay this balance using Amazon Payments, please click the button below.</p>{$button}"; $res = mail($to, $subject, $message, $headers); } message_register('E-mails have been sent'); variable_set('amazon_payment_last_email', date('Y-m-d')); return crm_url('payments', array('query' => array('tab' => 'billing'))); }
/** * Return a table showing account balances. * @param $opts An associative array of options. * @return A table object. */ function payment_accounts_table($opts) { $export = array_key_exists('export', $opts) && $opts['export'] ? true : false; $cids = payment_contact_filter(array('balance_due' => true)); $balances = payment_accounts(array('cid' => $cids)); $table = array('columns' => array(array('title' => 'Name'), array('title' => 'Email'), array('title' => 'Balance Owed')), 'rows' => array()); $contacts = crm_get_data('contact', array('cid' => $cids)); $cidToContact = crm_map($contacts, 'cid'); foreach ($balances as $cid => $balance) { $row = array(); $row[] = theme('contact_name', $cid, !$export); $row[] = $cidToContact[$cid]['email']; $row[] = payment_format_currency($balance); $table['rows'][] = $row; } return $table; }