public static function start_payment($invoice_id, $payment_amount, $invoice_payment_id, $user_id = false) { if ($invoice_id && $payment_amount && $invoice_payment_id) { // we are starting a payment via coinbase! // setup a pending payment and redirect to coinbase. $invoice_data = module_invoice::get_invoice($invoice_id); if (!$user_id) { $user_id = $invoice_data['user_id']; } if (!$user_id) { $user_id = isset($invoice_data['primary_user_id']) ? $invoice_data['primary_user_id'] : 0; } if (!$user_id) { $user_id = module_security::get_loggedin_id(); } $user_data = module_user::get_user($user_id); if (!$user_data || !strpos($user_data['email'], '@')) { die('Please ensure your user account has a valid email address before paying with coinbase'); } $invoice_payment_data = module_invoice::get_invoice_payment($invoice_payment_id); // we add the fee details to the invoice payment record so that the new invoice total can be calculated. $fee_percent = module_config::c('payment_method_coinbase_charge_percent', 0); $fee_amount = module_config::c('payment_method_coinbase_charge_amount', 0); $fee_description = module_config::c('payment_method_coinbase_charge_description', 'Coinbase Fee'); $fee_total = 0; if ($fee_percent != 0 || $fee_amount != 0) { $fee_total = module_invoice::calculate_fee($invoice_id, $invoice_data, $payment_amount, array('percent' => $fee_percent, 'amount' => $fee_amount, 'description' => $fee_description)); if ($fee_total != 0) { // add this percent/amount to the invoice payment $payment_amount = $payment_amount + $fee_total; update_insert('invoice_payment_id', $invoice_payment_id, 'invoice_payment', array('fee_percent' => $fee_percent, 'fee_amount' => $fee_amount, 'fee_description' => $fee_description, 'fee_total' => $fee_total, 'amount' => $payment_amount)); } } // we check if this payment is a recurring payment or a standard one off payment. if (module_config::c('payment_method_coinbase_subscriptions', 0)) { // we support subscriptions! // first check if the subscription module is active, and if this invoice is part of an active subscription. $is_subscription = false; if (class_exists('module_subscription', false)) { $subscription_history = get_single('subscription_history', 'invoice_id', $invoice_id); if ($subscription_history && $subscription_history['subscription_id']) { // this invoice is for a subscription! woo! // work out when we should bill for this subscription. $subscription = module_subscription::get_subscription($subscription_history['subscription_id']); $subscription_owner = module_subscription::get_subscription_owner($subscription_history['subscription_owner_id']); if ($subscription_owner['owner_table'] && $subscription_owner['owner_id']) { // work out when the next invoice will be generated for this subscription. $members_subscriptions = module_subscription::get_subscriptions_by($subscription_owner['owner_table'], $subscription_owner['owner_id']); if (isset($members_subscriptions[$subscription_history['subscription_id']])) { $member_subscription = $members_subscriptions[$subscription_history['subscription_id']]; // everything checks out! good to go.... // for now we just do a basic "EVERY X TIME" subscription // todo: work out how long until next generate date, and set that (possibly smaller) time period as the first portion of the subscription /*echo '<pre>'; print_r($subscription_history); print_r($subscription); print_r($subscription_owner); print_r($member_subscription); exit;*/ $is_subscription = array(); if ($subscription['days'] > 0) { $is_subscription['days'] = $subscription['days']; } if ($subscription['months'] > 0) { $is_subscription['months'] = $subscription['months']; } if ($subscription['years'] > 0) { $is_subscription['years'] = $subscription['years']; } if (count($is_subscription)) { $is_subscription['name'] = $subscription['name']; $is_subscription['id'] = $subscription_history['subscription_id']; } } } } } // todo: check if this invoice has a manual renewal date, perform subscription feature as above. if ($is_subscription) { // coinbase only supports these recurring methods: // daily, weekly, every_two_weeks, monthly, quarterly, and yearly // work out which one our days are at. $days = isset($is_subscription['days']) ? $is_subscription['days'] : 0; if (isset($is_subscription['months'])) { $days += $is_subscription['months'] * 30; unset($is_subscription['months']); } if (isset($is_subscription['years'])) { $days += $is_subscription['years'] * 365; unset($is_subscription['years']); } $is_subscription['days'] = $days; if ($days == 1) { $is_subscription['coinbase_period'] = 'daily'; } else { if ($days == 7 || $days == 6 || $days == 8) { $is_subscription['coinbase_period'] = 'weekly'; } else { if ($days == 14 || $days == 13 || $days == 15) { $is_subscription['coinbase_period'] = 'every_two_weeks'; } else { if ($days == 29 || $days == 30 || $days == 31) { $is_subscription['coinbase_period'] = 'monthly'; } else { if ($days >= 87 && $days <= 95) { $is_subscription['coinbase_period'] = 'quarterly'; } else { if ($days >= 363 && $days <= 370) { $is_subscription['coinbase_period'] = 'yearly'; } else { send_error('Someone tried to pay with coinbase but coinbase does not support a recurring subscription period of ' . $days . ' days. Only: daily, weekly, every_two_weeks, monthly, quarterly, and yearly '); $is_subscription = false; // not supported. } } } } } } } if ($is_subscription && isset($is_subscription['coinbase_period'])) { $invoice_payment_data = module_invoice::get_invoice_payment($invoice_payment_id); if (isset($invoice_payment_data['invoice_payment_subscription_id']) && (int) $invoice_payment_data['invoice_payment_subscription_id'] > 0) { // existing subscription already! // not really sure what to do here, just redirect to coinbase as if the user is doing it for the first time. $_REQUEST['payment_subscription'] = true; // hacks! } if (isset($_REQUEST['payment_subscription']) || module_config::c('payment_method_coinbase_force_subscription', 0)) { // user is setting up a subscription! yes!! // we create an entry in our database for this particular subscription // or if one exists for this payment already then we just continue with that (ie: the user is going in again to redo it) // setup a new subscription in the database for us. if (isset($invoice_payment_data['invoice_payment_subscription_id']) && (int) $invoice_payment_data['invoice_payment_subscription_id'] > 0) { $invoice_payment_subscription_id = $invoice_payment_data['invoice_payment_subscription_id']; } else { $invoice_payment_subscription_id = update_insert('invoice_payment_subscription_id', false, 'invoice_payment_subscription', array('status' => _INVOICE_SUBSCRIPTION_PENDING, 'days' => isset($is_subscription['days']) ? $is_subscription['days'] : 0, 'months' => isset($is_subscription['months']) ? $is_subscription['months'] : 0, 'years' => isset($is_subscription['years']) ? $is_subscription['years'] : 0, 'date_start' => '0000-00-00', 'date_last_pay' => '0000-00-00', 'date_next' => '0000-00-00')); update_insert('invoice_payment_id', $invoice_payment_id, 'invoice_payment', array('invoice_payment_subscription_id' => $invoice_payment_subscription_id)); } $description = _l('Recurring payment for %s %s', $is_subscription['name'], _l(str_replace('_', ' ', $is_subscription['coinbase_period']))); $subscription_name = $is_subscription['name']; unset($is_subscription['name']); // so reset/key cals below rosk. $subscription_id = $is_subscription['id']; unset($is_subscription['id']); // so reset/key cals below rosk. $currency = module_config::get_currency($invoice_payment_data['currency_id']); $currency_code = $currency['code']; include module_theme::include_ucm('includes/plugin_paymethod_coinbase/pages/coinbase_form.php'); exit; } else { if (isset($_REQUEST['payment_single'])) { // use is choosing to continue payment as a once off amount } else { // give the user an option $template = module_template::get_template_by_key('invoice_payment_subscription'); $template->page_title = htmlspecialchars($invoice_data['name']); $template->assign_values($invoice_payment_data); $template->assign_values(module_invoice::get_replace_fields($invoice_data['invoice_id'], $invoice_data)); $template->assign_values(array('invoice_payment_id' => $invoice_payment_id, 'payment_url' => module_invoice::link_public_pay($invoice_data['invoice_id']), 'payment_method' => 'paymethod_coinbase', 'payment_amount' => $payment_amount, 'pretty_payment_amount' => dollar($payment_amount, true, $invoice_data['currency_id']), 'subscription_period' => _l('%s days (%s)', $is_subscription['days'], $is_subscription['coinbase_period']), 'fee_amount' => dollar($fee_amount, true, $invoice_data['currency_id']), 'fee_total' => dollar($fee_total, true, $invoice_data['currency_id']), 'fee_percent' => $fee_percent, 'fee_description' => $fee_description)); echo $template->render('pretty_html'); exit; } } } } $description = _l('Payment for invoice %s', $invoice_data['name']); //self::coinbase_redirect($description,$payment_amount,$user_id,$invoice_payment_id,$invoice_id,$invoice_payment_data['currency_id']); $currency = module_config::get_currency($invoice_payment_data['currency_id']); $currency_code = $currency['code']; include module_theme::include_ucm('includes/plugin_paymethod_coinbase/pages/coinbase_form.php'); /*$template = new module_template(); ob_start(); $template->content = ob_get_clean(); echo $template->render('pretty_html');*/ exit; } return false; }
public static function get_statistics_subscription($search) { $subscriptions = module_subscription::get_subscriptions(); $return = array(); foreach ($subscriptions as $subscription) { $return[$subscription['subscription_id']] = $subscription; $return[$subscription['subscription_id']]['total_received'] = 0; $return[$subscription['subscription_id']]['total_received_count'] = 0; $return[$subscription['subscription_id']]['total_unpaid'] = 0; $return[$subscription['subscription_id']]['total_unpaid_count'] = 0; $return[$subscription['subscription_id']]['members'] = array(); $return[$subscription['subscription_id']]['customers'] = array(); // find all subscription_history's between these days $sql = "SELECT * "; $sql .= " FROM `" . _DB_PREFIX . "invoice` i"; $sql .= " RIGHT JOIN `" . _DB_PREFIX . "subscription_history` sh ON i.invoice_id = sh.invoice_id "; $sql .= " WHERE sh.subscription_id = " . (int) $subscription['subscription_id']; if (isset($search['date_from']) && $search['date_from']) { $sql .= " AND i.date_create >= '" . input_date($search['date_from']) . "'"; } if (isset($search['date_to']) && $search['date_to']) { $sql .= " AND i.date_create <= '" . input_date($search['date_to']) . "'"; } $res = qa($sql); // this is a list of invoices for these subscriptions from these date periods. //print_r($res); return; foreach ($res as $r) { $invoice = module_invoice::get_invoice($r['invoice_id']); $return[$subscription['subscription_id']]['total_received'] += $invoice['total_amount_paid']; if ($invoice['total_amount_paid'] > 0) { $return[$subscription['subscription_id']]['total_received_count']++; } $return[$subscription['subscription_id']]['total_unpaid'] += $invoice['total_amount_due']; if ($invoice['total_amount_due'] > 0) { $return[$subscription['subscription_id']]['total_unpaid_count']++; } if ($r['customer_id']) { if (!isset($return[$subscription['subscription_id']]['customers'][$r['customer_id']])) { $return[$subscription['subscription_id']]['customers'][$r['customer_id']] = array('customer_id' => $r['customer_id'], 'received_payments' => 0, 'unpaid_payments' => 0, 'received_total' => 0, 'unpaid_total' => 0); } if ($invoice['total_amount_paid'] > 0) { $return[$subscription['subscription_id']]['customers'][$r['customer_id']]['received_payments']++; } if ($invoice['total_amount_due'] > 0) { $return[$subscription['subscription_id']]['customers'][$r['customer_id']]['unpaid_payments']++; } $return[$subscription['subscription_id']]['customers'][$r['customer_id']]['received_total'] += $invoice['total_amount_paid']; $return[$subscription['subscription_id']]['customers'][$r['customer_id']]['unpaid_total'] += $invoice['total_amount_due']; } if ($r['member_id']) { if (!isset($return[$subscription['subscription_id']]['members'][$r['member_id']])) { $return[$subscription['subscription_id']]['members'][$r['member_id']] = array('member_id' => $r['member_id'], 'received_payments' => 0, 'unpaid_payments' => 0, 'received_total' => 0, 'unpaid_total' => 0); } if ($invoice['total_amount_paid'] > 0) { $return[$subscription['subscription_id']]['members'][$r['member_id']]['received_payments']++; } if ($invoice['total_amount_due'] > 0) { $return[$subscription['subscription_id']]['members'][$r['member_id']]['unpaid_payments']++; } $return[$subscription['subscription_id']]['members'][$r['member_id']]['received_total'] += $invoice['total_amount_paid']; $return[$subscription['subscription_id']]['members'][$r['member_id']]['unpaid_total'] += $invoice['total_amount_due']; } } } return $return; }
<?php /** * Copyright: dtbaker 2012 * Licence: Please check CodeCanyon.net for licence details. * More licence clarification available here: http://codecanyon.net/wiki/support/legal-terms/licensing-terms/ * Deploy: 9809 f200f46c2a19bb98d112f2d32a8de0c4 * Envato: 4ffca17e-861e-4921-86c3-8931978c40ca * Package Date: 2015-11-25 02:55:20 * IP Address: 67.79.165.254 */ $subscription_id = isset($_REQUEST['subscription_id']) && $_REQUEST['subscription_id'] != ''; if ($subscription_id) { $subscription = module_subscription::get_subscription($subscription_id); include 'subscription_admin_edit.php'; } else { include 'subscription_admin_list.php'; }
public static function start_payment($invoice_id, $payment_amount, $invoice_payment_id, $user_id = false) { if ($invoice_id && $payment_amount && $invoice_payment_id) { // we are starting a payment via paypal! // setup a pending payment and redirect to paypal. $invoice_data = module_invoice::get_invoice($invoice_id); if (!$user_id) { $user_id = $invoice_data['user_id']; } if (!$user_id) { $user_id = isset($invoice_data['primary_user_id']) ? $invoice_data['primary_user_id'] : 0; } $invoice_payment_data = module_invoice::get_invoice_payment($invoice_payment_id); // we add the fee details to the invoice payment record so that the new invoice total can be calculated. $fee_percent = module_config::c('payment_method_paypal_charge_percent', 0); $fee_amount = module_config::c('payment_method_paypal_charge_amount', 0); $fee_description = module_config::c('payment_method_paypal_charge_description', 'PayPal Fee'); $fee_total = 0; if ($fee_percent != 0 || $fee_amount != 0) { $fee_total = module_invoice::calculate_fee($invoice_id, $invoice_data, $payment_amount, array('percent' => $fee_percent, 'amount' => $fee_amount, 'description' => $fee_description)); if ($fee_total != 0) { // add this percent/amount to the invoice payment $payment_amount = $payment_amount + $fee_total; update_insert('invoice_payment_id', $invoice_payment_id, 'invoice_payment', array('fee_percent' => $fee_percent, 'fee_amount' => $fee_amount, 'fee_description' => $fee_description, 'fee_total' => $fee_total, 'amount' => $payment_amount)); } } // we check if this payment is a recurring payment or a standard one off payment. if (module_config::c('payment_method_paypal_subscriptions', 0)) { // we support subscriptions! // first check if the subscription module is active, and if this invoice is part of an active subscription. $is_subscription = false; if (class_exists('module_subscription', false)) { $subscription_history = get_single('subscription_history', 'invoice_id', $invoice_id); if ($subscription_history && $subscription_history['subscription_id']) { // this invoice is for a subscription! woo! // work out when we should bill for this subscription. $subscription = module_subscription::get_subscription($subscription_history['subscription_id']); $subscription_owner = module_subscription::get_subscription_owner($subscription_history['subscription_owner_id']); if ($subscription_owner['owner_table'] && $subscription_owner['owner_id']) { // work out when the next invoice will be generated for this subscription. $members_subscriptions = module_subscription::get_subscriptions_by($subscription_owner['owner_table'], $subscription_owner['owner_id']); if (isset($members_subscriptions[$subscription_history['subscription_id']])) { $member_subscription = $members_subscriptions[$subscription_history['subscription_id']]; // everything checks out! good to go.... // for now we just do a basic "EVERY X TIME" subscription // todo: work out how long until next generate date, and set that (possibly smaller) time period as the first portion of the subscription /*echo '<pre>'; print_r($subscription_history); print_r($subscription); print_r($subscription_owner); print_r($member_subscription); exit;*/ $is_subscription = array(); if ($subscription['days'] > 0) { $is_subscription['days'] = $subscription['days']; } if ($subscription['months'] > 0) { $is_subscription['months'] = $subscription['months']; } if ($subscription['years'] > 0) { $is_subscription['years'] = $subscription['years']; } if (count($is_subscription)) { $is_subscription['name'] = $subscription['name']; } } } } } // todo: check if this invoice has a manual renewal date, perform subscription feature as above. if ($is_subscription) { $bits = array(); if (isset($is_subscription['days']) && $is_subscription['days'] > 0) { $bits[] = _l('%s days', $is_subscription['days']); } if (isset($is_subscription['months']) && $is_subscription['months'] > 0) { $bits[] = _l('%s months', $is_subscription['months']); } if (isset($is_subscription['years']) && $is_subscription['years'] > 0) { $bits[] = _l('%s years', $is_subscription['years']); } $invoice_payment_data = module_invoice::get_invoice_payment($invoice_payment_id); if (isset($invoice_payment_data['invoice_payment_subscription_id']) && (int) $invoice_payment_data['invoice_payment_subscription_id'] > 0) { // existing subscription already! // not really sure what to do here, just redirect to paypal as if the user is doing it for the first time. $_REQUEST['payment_subscription'] = true; // hacks! } if (isset($_REQUEST['payment_subscription']) || module_config::c('payment_method_paypal_force_subscription', 0)) { // user is setting up a subscription! yes!! // we create an entry in our database for this particular subscription // or if one exists for this payment already then we just continue with that (ie: the user is going in again to redo it) // setup a new subscription in the database for us. if (isset($invoice_payment_data['invoice_payment_subscription_id']) && (int) $invoice_payment_data['invoice_payment_subscription_id'] > 0) { $invoice_payment_subscription_id = $invoice_payment_data['invoice_payment_subscription_id']; } else { $invoice_payment_subscription_id = update_insert('invoice_payment_subscription_id', false, 'invoice_payment_subscription', array('status' => _INVOICE_SUBSCRIPTION_PENDING, 'days' => isset($is_subscription['days']) ? $is_subscription['days'] : 0, 'months' => isset($is_subscription['months']) ? $is_subscription['months'] : 0, 'years' => isset($is_subscription['years']) ? $is_subscription['years'] : 0, 'date_start' => '0000-00-00', 'date_last_pay' => '0000-00-00', 'date_next' => '0000-00-00')); update_insert('invoice_payment_id', $invoice_payment_id, 'invoice_payment', array('invoice_payment_subscription_id' => $invoice_payment_subscription_id)); } $description = _l('Recurring payment for %s every %s', $is_subscription['name'], implode(', ', $bits)); unset($is_subscription['name']); // so reset/key cals below rosk. $currency = module_config::get_currency($invoice_payment_data['currency_id']); $url = 'https://www.' . (self::is_sandbox() ? 'sandbox.' : '') . 'paypal.com/cgi-bin/webscr?'; // if there are more than 1 recurring amounts then we convert it to days, as paypal only supports one time period. if (count($is_subscription) > 1) { $days = isset($is_subscription['days']) ? $is_subscription['days'] : 0; if (isset($is_subscription['months'])) { $days += $is_subscription['months'] * 30; unset($is_subscription['months']); } if (isset($is_subscription['years'])) { $days += $is_subscription['years'] * 365; unset($is_subscription['years']); } $is_subscription['days'] = $days; } reset($is_subscription); $time = key($is_subscription); if ($time == 'days') { $time = 'D'; } else { if ($time == 'months') { $time = 'M'; } else { if ($time == 'years') { $time = 'Y'; } } } $fields = array('cmd' => '_xclick-subscriptions', 'business' => module_config::c('payment_method_paypal_email', _ERROR_EMAIL), 'currency_code' => $currency['code'], 'item_name' => $description, 'no_shipping' => 1, 'page_style' => module_config::c('paypal_page_style', ''), 'return' => module_invoice::link_public_payment_complete($invoice_id), 'rm' => 1, 'cancel_return' => module_invoice::link_public($invoice_id), 'notify_url' => full_link(_EXTERNAL_TUNNEL . '?m=paymethod_paypal&h=ipn&method=paypal'), 'custom' => self::paypal_custom($user_id, $invoice_payment_id, $invoice_id, $invoice_payment_subscription_id), 'a3' => $payment_amount, 'p3' => current($is_subscription), 't3' => $time, 'src' => 1, 'sra' => 1, 'no_note' => 1); // is there a subscription trail period if (isset($subscription['settings']['trial_period']) && $subscription['settings']['trial_period'] > 0) { // we have to hacck the payment_amount here. // $payment_amount will be the discounted amount (eg: $5 instead of $10) // so we reverse that discounted amount for the real amount. $real_amount = $payment_amount - $fee_amount - (isset($subscription['settings']['trial_price_adjust']) ? $subscription['settings']['trial_price_adjust'] : 0); $real_fee_total = module_invoice::calculate_fee($invoice_id, $invoice_data, $real_amount, array('percent' => $fee_percent, 'amount' => $fee_amount, 'description' => $fee_description)); $real_amount += $real_fee_total; $fields['a3'] = $real_amount; $fields['a1'] = $payment_amount; // $real_amount + (isset($subscription['settings']['trial_price_adjust']) ? $subscription['settings']['trial_price_adjust'] : 0); $fields['p1'] = current($is_subscription); // * $subscription['settings']['trial_period']; $fields['t1'] = $time; } //echo '<pre>'; print_r($fields);exit; foreach ($fields as $key => $val) { $url .= $key . '=' . urlencode($val) . '&'; } //echo '<a href="'.$url.'">'.$url.'</a>';exit; redirect_browser($url); } else { if (isset($_REQUEST['payment_single'])) { // use is choosing to continue payment as a once off amount } else { // give the user an option module_template::init_template('invoice_payment_subscription', '<h2>Payment for Invoice {INVOICE_NUMBER}</h2> <p>Please choose from the available payment options below:</p> <form action="{PAYMENT_URL}" method="post"> <input type="hidden" name="invoice_payment_id" value="{INVOICE_PAYMENT_ID}"> <input type="hidden" name="payment_method" value="{PAYMENT_METHOD}"> <input type="hidden" name="payment_amount" value="{PAYMENT_AMOUNT}"> <p><input type="submit" name="payment_single" value="Pay a Once Off amount of {PRETTY_PAYMENT_AMOUNT}"></p> <p><input type="submit" name="payment_subscription" value="Setup Automatic Payments of {PRETTY_PAYMENT_AMOUNT} every {SUBSCRIPTION_PERIOD}"></p> </form> ', 'Used when a customer tries to pay an invoice that has a subscription option.', 'code'); $template = module_template::get_template_by_key('invoice_payment_subscription'); $template->page_title = htmlspecialchars($invoice_data['name']); $template->assign_values($invoice_payment_data); $template->assign_values(module_invoice::get_replace_fields($invoice_data['invoice_id'], $invoice_data)); $template->assign_values(array('invoice_payment_id' => $invoice_payment_id, 'payment_url' => module_invoice::link_public_pay($invoice_data['invoice_id']), 'payment_method' => 'paymethod_paypal', 'payment_amount' => $payment_amount, 'pretty_payment_amount' => dollar($payment_amount, true, $invoice_data['currency_id']), 'subscription_period' => implode(', ', $bits), 'fee_amount' => dollar($fee_amount, true, $invoice_data['currency_id']), 'fee_total' => dollar($fee_total, true, $invoice_data['currency_id']), 'fee_percent' => $fee_percent, 'fee_description' => $fee_description)); echo $template->render('pretty_html'); exit; } } } } $description = _l('Payment for Invoice %s', $invoice_data['name']); self::paypal_redirect($description, $payment_amount, $user_id, $invoice_payment_id, $invoice_id, $invoice_payment_data['currency_id']); return true; } return false; }
public static function run_cron($debug = false) { // we only want to perform these cron actions if we're after a certain time of day // because we dont want to be generating these renewals and sending them at midnight, can get confusing $after_time = module_config::c('invoice_automatic_after_time', 7); $time_of_day = date('G'); if ($time_of_day < $after_time) { if ($debug) { echo "Not performing automatic subscription operations until after {$after_time}:00 - it is currently {$time_of_day}:" . date('i') . "<br>\n"; } return; } // find all automatic subscriptions and renew them (if applicable) $sql = "SELECT * FROM `" . _DB_PREFIX . "subscription` s "; $sql .= " WHERE s.automatic_renew = 1"; $subscriptions = qa($sql); foreach ($subscriptions as $subscription) { if ($subscription['automatic_renew']) { if ($debug) { echo "<br>\nProcessing subscription renewals for subscription " . module_subscription::link_open($subscription['subscription_id'], true) . "<br>\n<br>\n"; } // find all the members/customers from this subscription //$members = module_subscription::get_subscribed_members($subscription['subscription_id']); //$customers = module_subscription::get_subscribed_customers($subscription['subscription_id']); $owners = module_subscription::get_subscribed_owners($subscription['subscription_id']); foreach ($owners as $member) { if (!$member['next_generation_date'] || $member['next_generation_date'] == '0000-00-00') { continue; } if (!$member['next_due_date'] || $member['next_due_date'] == '0000-00-00') { continue; } if ($debug) { echo "Doing: " . $member['owner_table'] . " " . $member['owner_id'] . "<br>\n"; } // check permissions for logged in users, dont want the cron to run when someone is logged in and no access to this account. if (module_security::is_logged_in()) { switch ($member['owner_table']) { case 'website': $website_perm_check = module_website::get_website($member['owner_id']); if (!$website_perm_check || $website_perm_check['website_id'] != $member['owner_id']) { continue 2; } if ($debug) { echo "permission pass for website: " . $website_perm_check['website_id']; } break; case 'customer': $customer_perm_check = module_customer::get_customer($member['owner_id']); if (!$customer_perm_check || $customer_perm_check['customer_id'] != $member['owner_id']) { continue 2; } if ($debug) { echo "permission pass for customer: " . $customer_perm_check['customer_id']; } break; } } // is the last invoice unpaid? $history = self::get_subscription_history($subscription['subscription_id'], $member['owner_table'], $member['owner_id']); $next_due_time_invoice_created = false; $invoice_unpaid = false; if (isset($member['recur_limit']) && (int) $member['recur_limit'] > 0 && count($history) >= (int) $member['recur_limit']) { if ($debug) { echo " - not renewing this one because it has hit our recur limit of " . $member['recur_limit'] . "<br>\n"; } continue; } foreach ($history as $h) { $last_invoice = module_invoice::get_invoice($h['invoice_id']); if (!$last_invoice || $last_invoice['date_cancel'] != '0000-00-00') { continue; } // check the new 'next_due_date' entry in the db table if (isset($h['from_next_due_date']) && $h['from_next_due_date'] && $h['from_next_due_date'] != '0000-00-00') { // we're using the new method of checking when an invoice was generated, rather than the confusing invoice 'date_create' check below if ($debug) { echo " - checking if next_due_date " . print_date($member['next_due_date']) . " matches subscription history from_next_due_date for invoice " . module_invoice::link_open($h['invoice_id'], true, $last_invoice) . " from_next_due_date: " . print_date($h['from_next_due_date']) . " (invoice create_date: " . print_date($last_invoice['date_create']) . ")<br>\n"; } if (print_date($member['next_due_date']) == print_date($h['from_next_due_date'])) { //print_date($last_invoice['date_create'])){ // this invoice is for the next due date. $next_due_time_invoice_created = $last_invoice; } } else { if ($debug) { echo " - checking if next_generation_date (" . print_date($member['next_generation_date']) . ") or next_due_date (" . print_date($member['next_due_date']) . ") matches invoice " . module_invoice::link_open($h['invoice_id'], true, $last_invoice) . " created date (" . print_date($last_invoice['date_create']) . ") <br>\n"; } if (print_date($member['next_generation_date']) == print_date($last_invoice['date_create']) || print_date($member['next_due_date']) == print_date($last_invoice['date_create'])) { //print_date($last_invoice['date_create'])){ // this invoice is for the next due date. $next_due_time_invoice_created = $last_invoice; } } if ($last_invoice['total_amount_due'] > 0) { $invoice_unpaid = true; } } //self::generate_subscription_invoice($subscription_id, $customer_hack, $member_id, $date, $amount) $next_due_time = strtotime($member['next_generation_date']); if ($debug) { echo " - next subscription time is " . $member['next_generation_date'] . " <br>\n"; } if ($next_due_time <= strtotime(date('Y-m-d')) && !$next_due_time_invoice_created) { if ($debug) { echo " - Yes its time to generate an invoice!<br>\n"; } if (module_config::c('invoice_auto_renew_only_paid_invoices', 1) && $invoice_unpaid) { if ($debug) { echo " - skipping generating renewal for " . $member['owner_table'] . " " . $member['owner_id'] . " because a previous subscription is unpaid <br>\n"; } continue; } // time to generate! woo! if ($debug) { echo " - generating subscription renewal for " . $member['owner_table'] . " " . $member['owner_id'] . "<br>\n"; } $invoice_id = self::generate_subscription_invoice($subscription['subscription_id'], $member['owner_table'], $member['owner_id'], $member['next_generation_date'], $subscription['amount']); if ($debug) { echo " - generated invoice " . module_invoice::link_open($invoice_id, true) . " for subscription <br>\n"; } if ($subscription['automatic_email']) { if ($debug) { echo " - emailing invoice to " . $member['owner_table'] . "... <br>\n"; } if (module_invoice::email_invoice_to_customer($invoice_id, $debug)) { if ($debug) { echo "send successfully <br>\n"; } } else { echo " - failed to send invoice " . module_invoice::link_open($invoice_id, true) . " to " . $member['owner_table'] . " <br>\n"; } } } else { if ($debug) { echo " - skipping generating renewal for " . $member['owner_table'] . " " . $member['owner_id'] . " because the due date has already been generated <br>\n"; } } } } } }
break; case _INVOICE_PAYMENT_TYPE_CREDIT: _e('Credit from customer %s', module_customer::link_open($invoice_payment_data['other_id'], true)); break; case _INVOICE_PAYMENT_TYPE_DEPOSIT: _e('Deposit from invoice %s', module_invoice::link_open($invoice_payment_data['other_id'], true)); break; case _INVOICE_PAYMENT_TYPE_OVERPAYMENT_CREDIT: _e('Assigning Credit to: %s', module_customer::link_open($invoice['customer_id'], true)); break; case _INVOICE_PAYMENT_TYPE_REFUND: _e('Refund: %s', htmlspecialchars($invoice_payment_data['method'])); break; case _INVOICE_PAYMENT_TYPE_SUBSCRIPTION_CREDIT: $subscription_owner = module_subscription::get_subscription_owner($invoice_payment_data['other_id']); _e('Subscription credit from %s', module_subscription::link_open($subscription_owner['subscription_id'], true)); break; } ?> </td> <td> <span class="currency"> <?php /* echo $invoice_payment_data['amount']>0 ? dollar($invoice_payment_data['amount'],true,$invoice['currency_id']) : dollar($invoice_payment_data['hours']*$invoice['hourly_rate'],true,$invoice['currency_id']); */ ?> <?php echo dollar($invoice_payment_data['amount'], true, $invoice_payment_data['currency_id']); // is there a fee? if ($invoice_payment_data['fee_total'] != 0) {
public static function start_payment($invoice_id, $payment_amount, $invoice_payment_id, $user_id = false) { if ($invoice_id && $payment_amount && $invoice_payment_id) { // we are starting a payment via stripe! // setup a pending payment and redirect to stripe. $invoice_data = module_invoice::get_invoice($invoice_id); if (!$user_id) { $user_id = $invoice_data['user_id']; } if (!$user_id) { $user_id = isset($invoice_data['primary_user_id']) ? $invoice_data['primary_user_id'] : 0; } if (!$user_id) { $user_id = module_security::get_loggedin_id(); } $user_data = module_user::get_user($user_id); if (!$user_data || !strpos($user_data['email'], '@')) { die('Please ensure your user account has a valid email address before paying with stripe'); } $invoice_payment_data = module_invoice::get_invoice_payment($invoice_payment_id); // we add the fee details to the invoice payment record so that the new invoice total can be calculated. $fee_percent = module_config::c('payment_method_stripe_charge_percent', 0); $fee_amount = module_config::c('payment_method_stripe_charge_amount', 0); $fee_description = module_config::c('payment_method_stripe_charge_description', 'Stripe Fee'); $fee_total = 0; if ($fee_percent != 0 || $fee_amount != 0) { $fee_total = module_invoice::calculate_fee($invoice_id, $invoice_data, $payment_amount, array('percent' => $fee_percent, 'amount' => $fee_amount, 'description' => $fee_description)); if ($fee_total != 0) { // add this percent/amount to the invoice payment $payment_amount = $payment_amount + $fee_total; update_insert('invoice_payment_id', $invoice_payment_id, 'invoice_payment', array('fee_percent' => $fee_percent, 'fee_amount' => $fee_amount, 'fee_description' => $fee_description, 'fee_total' => $fee_total, 'amount' => $payment_amount)); } } // we check if this payment is a recurring payment or a standard one off payment. if (module_config::c('payment_method_stripe_subscriptions', 0)) { // we support subscriptions! // first check if the subscription module is active, and if this invoice is part of an active subscription. $is_subscription = false; if (class_exists('module_subscription', false)) { $subscription_history = get_single('subscription_history', 'invoice_id', $invoice_id); if ($subscription_history && $subscription_history['subscription_id']) { // this invoice is for a subscription! woo! // work out when we should bill for this subscription. $subscription = module_subscription::get_subscription($subscription_history['subscription_id']); $subscription_owner = module_subscription::get_subscription_owner($subscription_history['subscription_owner_id']); if ($subscription_owner['owner_table'] && $subscription_owner['owner_id']) { // work out when the next invoice will be generated for this subscription. $members_subscriptions = module_subscription::get_subscriptions_by($subscription_owner['owner_table'], $subscription_owner['owner_id']); if (isset($members_subscriptions[$subscription_history['subscription_id']])) { $member_subscription = $members_subscriptions[$subscription_history['subscription_id']]; // everything checks out! good to go.... // for now we just do a basic "EVERY X TIME" subscription // todo: work out how long until next generate date, and set that (possibly smaller) time period as the first portion of the subscription /*echo '<pre>'; print_r($subscription_history); print_r($subscription); print_r($subscription_owner); print_r($member_subscription); exit;*/ $is_subscription = array(); if ($subscription['days'] > 0) { $is_subscription['days'] = $subscription['days']; } if ($subscription['months'] > 0) { $is_subscription['months'] = $subscription['months']; } if ($subscription['years'] > 0) { $is_subscription['years'] = $subscription['years']; } if (count($is_subscription)) { $is_subscription['name'] = $subscription['name']; $is_subscription['id'] = $subscription_history['subscription_id']; } } } } } // todo: check if this invoice has a manual renewal date, perform subscription feature as above. if ($is_subscription) { $bits = array(); if (isset($is_subscription['days']) && $is_subscription['days'] > 0) { $bits[] = _l('%s days', $is_subscription['days']); } if (isset($is_subscription['months']) && $is_subscription['months'] > 0) { $bits[] = _l('%s months', $is_subscription['months']); } if (isset($is_subscription['years']) && $is_subscription['years'] > 0) { $bits[] = _l('%s years', $is_subscription['years']); } $invoice_payment_data = module_invoice::get_invoice_payment($invoice_payment_id); if (isset($invoice_payment_data['invoice_payment_subscription_id']) && (int) $invoice_payment_data['invoice_payment_subscription_id'] > 0) { // existing subscription already! // not really sure what to do here, just redirect to stripe as if the user is doing it for the first time. $_REQUEST['payment_subscription'] = true; // hacks! } if (isset($_REQUEST['payment_subscription']) || module_config::c('payment_method_stripe_force_subscription', 0)) { // user is setting up a subscription! yes!! // we create an entry in our database for this particular subscription // or if one exists for this payment already then we just continue with that (ie: the user is going in again to redo it) // setup a new subscription in the database for us. if (isset($invoice_payment_data['invoice_payment_subscription_id']) && (int) $invoice_payment_data['invoice_payment_subscription_id'] > 0) { $invoice_payment_subscription_id = $invoice_payment_data['invoice_payment_subscription_id']; } else { $invoice_payment_subscription_id = update_insert('invoice_payment_subscription_id', false, 'invoice_payment_subscription', array('status' => _INVOICE_SUBSCRIPTION_PENDING, 'days' => isset($is_subscription['days']) ? $is_subscription['days'] : 0, 'months' => isset($is_subscription['months']) ? $is_subscription['months'] : 0, 'years' => isset($is_subscription['years']) ? $is_subscription['years'] : 0, 'date_start' => '0000-00-00', 'date_last_pay' => '0000-00-00', 'date_next' => '0000-00-00')); update_insert('invoice_payment_id', $invoice_payment_id, 'invoice_payment', array('invoice_payment_subscription_id' => $invoice_payment_subscription_id)); } $description = _l('Recurring payment for %s every %s', $is_subscription['name'], implode(', ', $bits)); $subscription_name = $is_subscription['name']; unset($is_subscription['name']); // so reset/key cals below rosk. $subscription_id = $is_subscription['id']; unset($is_subscription['id']); // so reset/key cals below rosk. $currency = module_config::get_currency($invoice_payment_data['currency_id']); // if there are more than 1 recurring amounts then we convert it to weeks, as stripe only supports one time period. if (count($is_subscription) > 1) { $days = isset($is_subscription['days']) ? $is_subscription['days'] : 0; if (isset($is_subscription['months'])) { $days += $is_subscription['months'] * 30; unset($is_subscription['months']); } if (isset($is_subscription['years'])) { $days += $is_subscription['years'] * 365; unset($is_subscription['years']); } $is_subscription['days'] = $days; } reset($is_subscription); $time = key($is_subscription); if ($time == 'days') { // convert days to weeks //$time = 'week'; $time = 'day'; $period = $is_subscription['days']; //$period = max(1,floor($is_subscription['days'] / 7)); } else { if ($time == 'months') { $time = 'month'; $period = $is_subscription['months']; } else { if ($time == 'years') { $time = 'year'; $period = $is_subscription['years']; } else { die('Failed to create subscription, invalid settings'); } } } $stripe_amount = $payment_amount * 100; ini_set('display_errors', true); ini_set('error_reporting', E_ALL); // create or retrieve this subscription. require_once 'includes/plugin_paymethod_stripe/stripe-php/lib/Stripe.php'; $stripe = array("secret_key" => module_config::c('payment_method_stripe_secret_key'), "publishable_key" => module_config::c('payment_method_stripe_publishable_key')); Stripe::setApiKey($stripe['secret_key']); $stripe_plan_id = 'sub_' . $subscription_id; $stripe_plan = false; if ($stripe_plan_id) { // get this plan from stripe, and check it's still valid: try { $stripe_plan = Stripe_Plan::retrieve($stripe_plan_id); } catch (Exception $e) { //print_r($e); } if ($stripe_plan && $stripe_plan->interval == $time && $stripe_plan->interval_count == $period && $stripe_plan->amount == $stripe_amount) { // still have a valid plan! yes! } else { // plan no longer exists or has changed $stripe_plan = false; } } if (!$stripe_plan) { try { $settings = array("amount" => $stripe_amount, "interval" => $time, 'interval_count' => $period, "name" => $subscription_name, "currency" => $currency['code'], "id" => $stripe_plan_id, 'metadata' => array('subscription_id' => $subscription_id)); $stripe_plan = Stripe_Plan::create($settings); } catch (Exception $e) { //print_r($e); } // print_r($stripe_plan); } if ($stripe_plan) { // right to go! // display the stripe payment form (same as stripe_form.php, just we do a subscription rather than once off payment) //self::stripe_redirect($description,$payment_amount,$user_id,$invoice_payment_id,$invoice_id,$invoice_payment_data['currency_id']); $currency = module_config::get_currency($invoice_payment_data['currency_id']); $currency_code = $currency['code']; $template = new module_template(); ob_start(); ?> <h1><?php echo htmlspecialchars($description); ?> </h1> <form action="<?php echo full_link(_EXTERNAL_TUNNEL . '?m=paymethod_stripe&h=pay_subscription&method=stripe'); ?> " method="post"> <input type="hidden" name="invoice_payment_subscription_id" value="<?php echo $invoice_payment_subscription_id; ?> "> <input type="hidden" name="invoice_payment_id" value="<?php echo $invoice_payment_id; ?> "> <input type="hidden" name="invoice_id" value="<?php echo $invoice_id; ?> "> <input type="hidden" name="stripe_plan_id" value="<?php echo $stripe_plan_id; ?> "> <input type="hidden" name="description" value="<?php echo htmlspecialchars($description); ?> "> <input type="hidden" name="user_id" value="<?php echo htmlspecialchars($user_id); ?> "> <script src="https://checkout.stripe.com/v2/checkout.js" class="stripe-button" data-key="<?php echo $stripe['publishable_key']; ?> " data-amount="<?php echo $payment_amount * 100; ?> " <?php if (isset($user_data['email']) && strlen($user_data['email'])) { ?> data-email="<?php echo htmlspecialchars($user_data['email']); ?> " <?php } ?> data-currency="<?php echo htmlspecialchars($currency_code); ?> " data-label="<?php _e('Pay %s by Credit Card', dollar($payment_amount, true, $invoice_payment_data['currency_id'])); ?> " data-description="<?php echo htmlspecialchars($description); ?> "></script> </form> <p> </p> <p> <a href="<?php echo module_invoice::link_public($invoice_id); ?> "><?php _e("Cancel"); ?> </a> </p> <?php $template->content = ob_get_clean(); echo $template->render('pretty_html'); exit; } else { die('Failed to create stripe plan. Please check settings: ' . var_export($stripe_plan, true)); } } else { if (isset($_REQUEST['payment_single'])) { // use is choosing to continue payment as a once off amount } else { // give the user an option module_template::init_template('invoice_payment_subscription', '<h2>Payment for Invoice {INVOICE_NUMBER}</h2> <p>Please choose from the available payment options below:</p> <form action="{PAYMENT_URL}" method="post"> <input type="hidden" name="invoice_payment_id" value="{INVOICE_PAYMENT_ID}"> <input type="hidden" name="payment_method" value="{PAYMENT_METHOD}"> <input type="hidden" name="payment_amount" value="{PAYMENT_AMOUNT}"> <p><input type="submit" name="payment_single" value="Pay a Once Off amount of {PRETTY_PAYMENT_AMOUNT}"></p> <p><input type="submit" name="payment_subscription" value="Setup Automatic Payments of {PRETTY_PAYMENT_AMOUNT} every {SUBSCRIPTION_PERIOD}"></p> </form> ', 'Used when a customer tries to pay an invoice that has a subscription option.', 'code'); $template = module_template::get_template_by_key('invoice_payment_subscription'); $template->page_title = htmlspecialchars($invoice_data['name']); $template->assign_values($invoice_payment_data); $template->assign_values(module_invoice::get_replace_fields($invoice_data['invoice_id'], $invoice_data)); $template->assign_values(array('invoice_payment_id' => $invoice_payment_id, 'payment_url' => module_invoice::link_public_pay($invoice_data['invoice_id']), 'payment_method' => 'paymethod_stripe', 'payment_amount' => $payment_amount, 'pretty_payment_amount' => dollar($payment_amount, true, $invoice_data['currency_id']), 'subscription_period' => implode(', ', $bits), 'fee_amount' => dollar($fee_amount, true, $invoice_data['currency_id']), 'fee_total' => dollar($fee_total, true, $invoice_data['currency_id']), 'fee_percent' => $fee_percent, 'fee_description' => $fee_description)); echo $template->render('pretty_html'); exit; } } } } $description = _l('Payment for invoice %s', $invoice_data['name']); //self::stripe_redirect($description,$payment_amount,$user_id,$invoice_payment_id,$invoice_id,$invoice_payment_data['currency_id']); $currency = module_config::get_currency($invoice_payment_data['currency_id']); $currency_code = $currency['code']; $template = new module_template(); ob_start(); include module_theme::include_ucm('includes/plugin_paymethod_stripe/pages/stripe_form.php'); $template->content = ob_get_clean(); echo $template->render('pretty_html'); exit; } return false; }
_e('Invoices'); ?> </th> <th><?php _e('Total Received'); ?> </th> <th><?php _e('Total Unpaid'); ?> </th> </tr> </thead> <?php foreach ($subscribed_owners as $subscribed_customer) { $history = module_subscription::get_subscription_history($subscription_id, $subscribed_customer['owner_table'], $subscribed_customer['owner_id']); $total_paid = $total_unpaid = array(); foreach ($history as $h_id => $h) { if ($h['invoice_id']) { $invoice = module_invoice::get_invoice($h['invoice_id'], true); if ($invoice['date_cancel'] && $invoice['date_cancel'] != '0000-00-00') { // invoice cancelled, ignore from listing unset($history[$h_id]); continue; } if ($h['paid_date'] && $h['paid_date'] != '0000-00-00') { if (!isset($total_paid[$invoice['currency_id']])) { $total_paid[$invoice['currency_id']] = 0; } $total_paid[$invoice['currency_id']] += $h['amount']; }
// find the groups for this website. $groups = module_group::get_groups_search(array('owner_table' => 'website', 'owner_id' => $website['website_id'])); $g = array(); foreach ($groups as $group) { $g[] = $group['name']; } echo htmlspecialchars(implode(', ', $g)); } }); } if (class_exists('module_extra', false)) { $table_manager->display_extra('website', function ($website) { module_extra::print_table_data('website', $website['website_id']); }); } if (class_exists('module_subscription', false)) { $table_manager->display_subscription('website', function ($website) { module_subscription::print_table_data('website', $website['website_id']); }); } $table_manager->set_columns($columns); $table_manager->row_callback = function ($row_data) { // load the full vendor data before displaying each row so we have access to more details return module_website::get_website($row_data['website_id']); }; $table_manager->set_rows($websites); $table_manager->pagination = true; $table_manager->print_table(); ?> </form>
public static function handle_bulk_delete_double_optin($rows) { $delete = array(); foreach ($rows as $member_to_delete) { $newsletter_member_id = module_newsletter::member_from_email($member_to_delete, false); if ($newsletter_member_id) { if ($res = module_newsletter::is_member_unsubscribed($newsletter_member_id, $member_to_delete)) { if (class_exists('module_subscription', false)) { // check this isn't a member from a subscription or something. $sub = module_subscription::get_subscriptions_by('member', $member_to_delete['member_id']); if (count($sub)) { continue; } } if (isset($res['reason']) && $res['reason'] == 'doubleoptin') { //delete this onee! $delete[] = array('member_id' => $member_to_delete['member_id']); } } } } if (module_form::confirm_delete('bulk_optin_array', "Really delete all " . count($delete) . " failed double-opt-in members?", $_SERVER['REQUEST_URI'])) { foreach ($delete as $member_to_delete) { self::delete_member($member_to_delete['member_id']); } set_message("Selected members deleted successfully"); redirect_browser(self::link_open(false)); } }
public function print_table() { $this->process_data(); $colspan = 0; if (!$this->inline_table) { ?> <div class="box <?php echo module_theme::get_config('adminlte_boxstyle', 'box-solid'); ?> "> <?php /*if($this->pagination){ ?> <div class="box-header clearfix"> <div class="row"><div class="col-xs-6"> </div><div class="col-xs-6 text-right"> <?php echo $this->rows['summary']; ?> </div></div> </div> <?php }*/ ?> <div class="box-body table-responsive <?php echo module_theme::get_config('adminlte_tablefullwidth', 1) ? 'no-padding' : ''; ?> "> <?php } ?> <table class="<?php echo $this->table_class; echo module_theme::get_config('adminlte_tablestripe', '1') ? ' table-striped' : ''; echo module_theme::get_config('adminlte_tableborder', '0') ? ' table-bordered' : ''; ?> "<?php echo $this->table_id ? ' id="' . $this->table_id . '"' : ''; ?> > <thead> <tr class="title"> <?php foreach ($this->columns as $column_id => $column_data) { $title = is_array($column_data) ? $column_data['title'] : $column_data; $colspan++; ?> <th id="<?php echo $column_id; ?> "><?php echo _l($title); ?> </th> <?php } if (class_exists('module_extra', false) && count($this->extra_fields)) { foreach ($this->extra_fields as $extra_field) { $colspan += module_extra::print_table_header($extra_field['type']); } } if (class_exists('module_subscription', false) && count($this->subscription_fields)) { foreach ($this->subscription_fields as $extra_field) { module_subscription::print_table_header($extra_field['type']); $colspan++; } } ?> </tr> </thead> <?php if (count($this->header_rows)) { ?> <thead class="summary"> <?php foreach ($this->header_rows as $row) { $this->print_footer_row($row); } ?> </thead> <?php } ?> <tbody> <?php if (!count($this->rows['rows'])) { if ($this->blank_message) { ?> <tr> <td colspan="<?php echo $colspan; ?> " class="blank_message" style="text-align: center"><?php _e($this->blank_message); ?> </td> </tr> <?php } } else { foreach ($this->rows['rows'] as $row) { $this->print_row($row); } } ?> </tbody> <?php if (count($this->footer_rows)) { ?> <tfoot class="summary"> <?php foreach ($this->footer_rows as $row) { $this->print_footer_row($row); } ?> </tfoot> <?php } ?> </table> <?php if (!$this->inline_table) { ?> </div> <?php } if ($this->pagination && (!$this->pagination_hide_single_page || $this->pagination_hide_single_page && $this->rows['page_numbers'] > 1)) { ?> <div class="box-footer clearfix"> <div class="row"><div class="col-xs-6"> <?php // regex and change the default pagination html output to something nicer, default is: /* <div class="pagination_links"><span> « Prev | </span> <span><a href="/ucm/demo/customer.customer_admin_list/?leads=1&pgtable=0#t_table" rel="0" class="current">1</a></span> <span><a href="/ucm/demo/customer.customer_admin_list/?leads=1&pgtable=1#t_table" rel="1" class="">2</a></span> <span><a href="/ucm/demo/customer.customer_admin_list/?leads=1&pgtable=2#t_table" rel="2" class="">3</a></span> <span><a href="/ucm/demo/customer.customer_admin_list/?leads=1&pgtable=3#t_table" rel="3" class="">4</a></span> | <span><a href="/ucm/demo/customer.customer_admin_list/?leads=1&pgtable=1#t_table" rel="1">Next »</a><span> </span></span></div> */ $this->rows['links'] = str_replace('<div class="pagination_links">', '<div class="pagination_links paging_bootstrap pagination-sm no-margin"><ul class="pagination pagination-sm">', $this->rows['links']); $this->rows['links'] = str_replace('</div>', '</ul></div>', $this->rows['links']); //$this->rows['links'] = str_replace('pagination_links','pagination_links paging_bootstrap',$this->rows['links']); $this->rows['links'] = str_replace('|', '', $this->rows['links']); $this->rows['links'] = str_replace('...', '<li class="disabled"><a href="#">...</a></li>', $this->rows['links']); if (preg_match_all('#<span>(.*)</span>#imsU', $this->rows['links'], $matches)) { foreach ($matches[0] as $key => $val) { $li_class = strpos($val, 'current') ? 'active' : ''; if (strpos($matches[1][$key], '<a') === false) { $li_class = 'disabled'; $matches[1][$key] = '<a href="#">' . $matches[1][$key] . '</a>'; } $this->rows['links'] = str_replace($val, '<li class="' . $li_class . '">' . $matches[1][$key] . '</li>', $this->rows['links']); } } echo $this->rows['links']; ?> </div><div class="col-xs-6 text-right"> <?php echo $this->rows['summary']; ?> </div></div> </div> <?php } if (!$this->inline_table) { ?> </div> <?php } }
public function external_hook($hook) { switch ($hook) { case 'public_signup_form': $signup_form = module_template::get_template_by_key('customer_signup_form_wrapper'); $signup_form->page_title = $signup_form->description; $signup_form->assign_values(array('signup_form' => self::get_customer_signup_form_html())); echo $signup_form->render('pretty_html'); exit; case 'public_signup': // sign out if testing. if (module_security::is_logged_in()) { set_message('Logged out due to signup'); module_security::logout(); } $result = array('messages' => array()); function customer_signup_complete($result) { if (isset($_REQUEST['via_ajax'])) { echo json_encode($result); } else { echo implode('<br/>', $result['messages']); } exit; } if (!module_config::c('customer_signup_allowed', 0)) { $result['error'] = 1; $result['messages'][] = 'Customer signup disabled'; customer_signup_complete($result); } //recaptcha on signup form. if (module_config::c('captcha_on_signup_form', 0)) { if (!module_captcha::check_captcha_form()) { $result['error'] = 1; $result['messages'][] = 'Captcha fail, please go back and enter correct captcha code.'; customer_signup_complete($result); } } $customer = isset($_POST['customer']) && is_array($_POST['customer']) ? $_POST['customer'] : array(); $contact = isset($_POST['contact']) && is_array($_POST['contact']) ? $_POST['contact'] : array(); $contact_extra = isset($contact['extra']) && is_array($contact['extra']) ? $contact['extra'] : array(); $contact_group = isset($contact['group_ids']) && is_array($contact['group_ids']) ? $contact['group_ids'] : array(); $customer_extra = isset($customer['extra']) ? $customer['extra'] : array(); $customer_group = isset($customer['group_ids']) && is_array($customer['group_ids']) ? $customer['group_ids'] : array(); $address = isset($_POST['address']) ? $_POST['address'] : array(); $website = isset($_POST['website']) ? $_POST['website'] : array(); $website_extra = isset($website['extra']) ? $website['extra'] : array(); $website_group = isset($website['group_ids']) && is_array($website['group_ids']) ? $website['group_ids'] : array(); $job = isset($_POST['job']) ? $_POST['job'] : array(); $job_extra = isset($job['extra']) ? $job['extra'] : array(); $subscription = isset($_POST['subscription']) ? $_POST['subscription'] : array(); // sanatise possibly problematic fields: // customer: $allowed = array('name', 'last_name', 'customer_name', 'email', 'phone', 'mobile', 'extra', 'type'); foreach ($customer as $key => $val) { if (!in_array($key, $allowed)) { unset($customer[$key]); } } if (isset($customer['type']) && $customer['type'] != _CUSTOMER_TYPE_NORMAL && $customer['type'] != _CUSTOMER_TYPE_LEAD) { unset($customer['type']); } // added multiple contact support in the form of arrays. $contact_fields = array('name', 'last_name', 'email', 'phone'); if (module_config::c('customer_signup_password', 0)) { $contact_fields[] = 'password'; } foreach ($contact_fields as $multi_value) { if (isset($contact[$multi_value])) { if (!is_array($contact[$multi_value])) { $contact[$multi_value] = array($contact[$multi_value]); } } else { if (isset($customer[$multi_value])) { $contact[$multi_value] = array($customer[$multi_value]); } else { $contact[$multi_value] = array(); } } } $valid_contact_email = false; $name_fallback = false; $primary_email = false; foreach ($contact['email'] as $contact_key => $email) { if (!$name_fallback && isset($contact['name'][$contact_key])) { $name_fallback = $contact['name'][$contact_key]; } $contact['email'][$contact_key] = filter_var(strtolower(trim($email)), FILTER_VALIDATE_EMAIL); if ($contact['email'][$contact_key]) { $valid_contact_email = true; if (!$primary_email) { $primary_email = $contact['email'][$contact_key]; // set the primary contact details here by adding them to the master customer array foreach ($contact_fields as $primary_contact_field) { $customer[$primary_contact_field] = isset($contact[$primary_contact_field][$contact_key]) ? $contact[$primary_contact_field][$contact_key] : ''; unset($contact[$primary_contact_field][$contact_key]); } } } } // start error checking / required fields if (!isset($customer['customer_name']) || !strlen($customer['customer_name'])) { $customer['customer_name'] = $name_fallback; } if (!strlen($customer['customer_name'])) { $result['error'] = 1; $result['messages'][] = "Failed, please go back and provide a customer name."; } if (!$valid_contact_email || !$primary_email) { $result['error'] = 1; $result['messages'][] = "Failed, please go back and provide an email address."; } // check all posted required fields. function check_required($postdata, $messages = array()) { if (is_array($postdata)) { foreach ($postdata as $key => $val) { if (strpos($key, '_required') && strlen($val)) { $required_key = str_replace('_required', '', $key); if (!isset($postdata[$required_key]) || !$postdata[$required_key]) { $messages[] = 'Required field missing: ' . htmlspecialchars($val); } } if (is_array($val)) { $messages = check_required($val, $messages); } } } return $messages; } $messages = check_required($_POST); if (count($messages)) { $result['error'] = 1; $result['messages'] = array_merge($result['messages'], $messages); } if (isset($result['error'])) { customer_signup_complete($result); } // end error checking / required fields. // check if this customer already exists in the system, based on email address $customer_id = false; $creating_new = true; $_REQUEST['user_id'] = 0; if (isset($customer['email']) && strlen($customer['email']) && !module_config::c('customer_signup_always_new', 0)) { $users = module_user::get_contacts(array('email' => $customer['email'])); foreach ($users as $user) { if (isset($user['customer_id']) && (int) $user['customer_id'] > 0) { // this user exists as a customer! yey! // add them to this listing. $customer_id = $user['customer_id']; $creating_new = false; $_REQUEST['user_id'] = $user['user_id']; // dont let signups update existing passwords. if (isset($customer['password'])) { unset($customer['password']); } if (isset($customer['new_password'])) { unset($customer['new_password']); } } } } $_REQUEST['extra_customer_field'] = array(); $_REQUEST['extra_user_field'] = array(); module_extra::$config['allow_new_keys'] = false; module_extra::$config['delete_existing_empties'] = false; // save customer extra fields. if (count($customer_extra)) { // format the address so "save_customer" handles the save for us foreach ($customer_extra as $key => $val) { $_REQUEST['extra_customer_field'][] = array('key' => $key, 'val' => $val); } } // save customer and customer contact details: $customer_id = $this->save_customer($customer_id, $customer); if (!$customer_id) { $result['error'] = 1; $result['messages'][] = 'System error: failed to create customer.'; customer_signup_complete($result); } $customer_data = module_customer::get_customer($customer_id); // todo - merge primary and secondary contact/extra/group saving into a single loop if (!$customer_data['primary_user_id']) { $result['error'] = 1; $result['messages'][] = 'System error: Failed to create customer contact.'; customer_signup_complete($result); } else { $role_id = module_config::c('customer_signup_role', 0); if ($role_id > 0) { module_user::add_user_to_role($customer_data['primary_user_id'], $role_id); } // save contact extra data (repeated below for additional contacts) if (isset($contact_extra[0]) && count($contact_extra[0])) { $_REQUEST['extra_user_field'] = array(); foreach ($contact_extra[0] as $key => $val) { $_REQUEST['extra_user_field'][] = array('key' => $key, 'val' => $val); } module_extra::save_extras('user', 'user_id', $customer_data['primary_user_id']); } // save contact groups if (isset($contact_group[0]) && count($contact_group[0])) { foreach ($contact_group[0] as $group_id => $tf) { if ($tf) { module_group::add_to_group($group_id, $customer_data['primary_user_id'], 'user'); } } } } foreach ($contact['email'] as $contact_key => $email) { // add any additional contacts to the customer. $users = module_user::get_contacts(array('email' => $email, 'customer_id' => $customer_id)); if (count($users)) { // this contact already exists for this customer, dont update/change it. continue; } $new_contact = array('customer_id' => $customer_id); foreach ($contact_fields as $primary_contact_field) { $new_contact[$primary_contact_field] = isset($contact[$primary_contact_field][$contact_key]) ? $contact[$primary_contact_field][$contact_key] : ''; } // dont let additional contacts have passwords. if (isset($new_contact['password'])) { unset($new_contact['password']); } if (isset($new_contact['new_password'])) { unset($new_contact['new_password']); } global $plugins; $contact_user_id = $plugins['user']->create_user($new_contact, 'signup'); if ($contact_user_id) { $role_id = module_config::c('customer_signup_role', 0); if ($role_id > 0) { module_user::add_user_to_role($contact_user_id, $role_id); } // save contact extra data (repeated below for primary contacts) if (isset($contact_extra[$contact_key]) && count($contact_extra[$contact_key])) { $_REQUEST['extra_user_field'] = array(); foreach ($contact_extra[$contact_key] as $key => $val) { $_REQUEST['extra_user_field'][] = array('key' => $key, 'val' => $val); } module_extra::save_extras('user', 'user_id', $contact_user_id); } // save contact groups if (isset($contact_group[$contact_key]) && count($contact_group[$contact_key])) { foreach ($contact_group[$contact_key] as $group_id => $tf) { if ($tf) { module_group::add_to_group($group_id, $contact_user_id, 'user'); } } } } } if (count($customer_group)) { // format the address so "save_customer" handles the save for us foreach ($customer_group as $group_id => $tf) { if ($tf) { module_group::add_to_group($group_id, $customer_id, 'customer'); } } } $note_keys = array('customer', 'website', 'job', 'address', 'subscription'); $note_text = _l('Customer signed up from Signup Form:'); $note_text .= "\n\n"; foreach ($note_keys as $note_key) { $note_text .= "\n" . ucwords(_l($note_key)) . "\n"; if (isset($_POST[$note_key]) && is_array($_POST[$note_key])) { foreach ($_POST[$note_key] as $post_key => $post_val) { $note_text .= "\n - " . _l($post_key) . ": "; if (is_array($post_val)) { foreach ($post_val as $p => $v) { $note_text .= "\n - - " . _l($p) . ': ' . $v; } } else { $note_text .= $post_val; } } } } $note_data = array('note_id' => false, 'owner_id' => $customer_id, 'owner_table' => 'customer', 'note_time' => time(), 'note' => $note_text, 'rel_data' => module_customer::link_open($customer_id), 'reminder' => 0, 'user_id' => 0); update_insert('note_id', false, 'note', $note_data); // save customer address fields. if (count($address)) { $address_db = module_address::get_address($customer_id, 'customer', 'physical'); $address_id = $address_db && isset($address_db['address_id']) ? (int) $address_db['address_id'] : false; $address['owner_id'] = $customer_id; $address['owner_table'] = 'customer'; $address['address_type'] = 'physical'; // we have post data to save, write it to the table!! module_address::save_address($address_id, $address); } // website: $allowed = array('url', 'name', 'extra', 'notes'); foreach ($website as $key => $val) { if (!in_array($key, $allowed)) { unset($website[$key]); } } $website['url'] = isset($website['url']) ? strtolower(trim($website['url'])) : ''; $website_id = 0; if (count($website) && class_exists('module_website', false) && module_website::is_plugin_enabled()) { if (strlen($website['url'])) { // see if website already exists, don't create or update existing one for now. $existing_websites = module_website::get_websites(array('customer_id' => $customer_id, 'url' => $website['url'])); foreach ($existing_websites as $existing_website) { $website_id = $existing_website['website_id']; } } // echo $website_id;echo $website['url']; print_r($website_extra);exit; if (!$website_id) { $website_data = module_website::get_website($website_id); $website_data['url'] = isset($website['url']) ? $website['url'] : 'N/A'; $website_data['name'] = isset($website['url']) ? $website['url'] : 'N/A'; $website_data['customer_id'] = $customer_id; $website_id = update_insert('website_id', false, 'website', $website_data); // save website extra data. if ($website_id && count($website_extra)) { $_REQUEST['extra_website_field'] = array(); foreach ($website_extra as $key => $val) { $_REQUEST['extra_website_field'][] = array('key' => $key, 'val' => $val); } module_extra::save_extras('website', 'website_id', $website_id); } if ($website_id && isset($website['notes']) && strlen($website['notes'])) { // add notes to this website. $note_data = array('note_id' => false, 'owner_id' => $website_id, 'owner_table' => 'website', 'note_time' => time(), 'note' => $website['notes'], 'rel_data' => module_website::link_open($website_id), 'reminder' => 0, 'user_id' => $customer_data['primary_user_id']); $note_id = update_insert('note_id', false, 'note', $note_data); } } if ($website_id) { if (count($website_group)) { // format the address so "save_customer" handles the save for us foreach ($website_group as $group_id => $tf) { if ($tf) { module_group::add_to_group($group_id, $website_id, 'website'); } } } } } // generate jobs for this customer. $job_created = array(); if ($job && isset($job['type']) && is_array($job['type'])) { if (module_config::c('customer_signup_any_job_type', 0)) { foreach ($job['type'] as $type_name) { // we have a match in our system. create the job. $job_data = module_job::get_job(false); $job_data['type'] = $type_name; if (!$job_data['name']) { $job_data['name'] = $type_name; } $job_data['website_id'] = $website_id; $job_data['customer_id'] = $customer_id; $job_id = update_insert('job_id', false, 'job', $job_data); // todo: add default tasks for this job type. $job_created[] = $job_id; } } else { foreach (module_job::get_types() as $type_id => $type) { foreach ($job['type'] as $type_name) { if ($type_name == $type) { // we have a match in our system. create the job. $job_data = module_job::get_job(false); $job_data['type'] = $type; if (!$job_data['name']) { $job_data['name'] = $type; } $job_data['website_id'] = $website_id; $job_data['customer_id'] = $customer_id; $job_id = update_insert('job_id', false, 'job', $job_data); // todo: add default tasks for this job type. $job_created[] = $job_id; } } } } if (count($job_created) && count($job_extra)) { // save job extra data. foreach ($job_created as $job_created_id) { if ($job_created_id && count($job_extra)) { $_REQUEST['extra_job_field'] = array(); foreach ($job_extra as $key => $val) { $_REQUEST['extra_job_field'][] = array('key' => $key, 'val' => $val); } module_extra::save_extras('job', 'job_id', $job_created_id); } } } } // save files against customer $uploaded_files = array(); if (isset($_FILES['customerfiles']) && isset($_FILES['customerfiles']['tmp_name'])) { foreach ($_FILES['customerfiles']['tmp_name'] as $file_id => $tmp_file) { if (is_uploaded_file($tmp_file)) { // save to file module for this customer $file_name = basename($_FILES['customerfiles']['name'][$file_id]); if (strlen($file_name)) { $file_path = 'includes/plugin_file/upload/' . md5(time() . $file_name); if (move_uploaded_file($tmp_file, $file_path)) { // success! write to db. $file_data = array('customer_id' => $customer_id, 'job_id' => current($job_created), 'website_id' => $website_id, 'status' => module_config::c('file_default_status', 'Uploaded'), 'pointers' => false, 'description' => "Uploaded from Customer Signup form", 'file_time' => time(), 'file_name' => $file_name, 'file_path' => $file_path, 'file_url' => false); $file_id = update_insert('file_id', false, 'file', $file_data); $uploaded_files[] = $file_id; } } } } } // we create subscriptions for this customer/website (if none already exist) $subscription['subscription_name'] = array(); $subscription['subscription_invoice'] = array(); if (class_exists('module_subscription', false) && module_subscription::is_plugin_enabled() && isset($subscription['for']) && isset($subscription['subscriptions'])) { if ($subscription['for'] == 'website' && $website_id > 0) { $owner_table = 'website'; $owner_id = $website_id; } else { $owner_table = 'customer'; $owner_id = $customer_id; } $available_subscriptions = module_subscription::get_subscriptions(); $members_subscriptions = module_subscription::get_subscriptions_by($owner_table, $owner_id); foreach ($subscription['subscriptions'] as $subscription_id => $tf) { if (isset($available_subscriptions[$subscription_id])) { if (isset($members_subscriptions[$subscription_id])) { // we don't allow a member to sign up to the same subscription twice (just yet) } else { $subscription['subscription_name'][$subscription_id] = $available_subscriptions[$subscription_id]['name']; $start_date = date('Y-m-d'); $start_modifications = module_config::c('customer_signup_subscription_start', ''); if ($start_modifications == 'hidden') { $start_modifications = isset($_REQUEST['customer_signup_subscription_start']) ? $_REQUEST['customer_signup_subscription_start'] : ''; } if (!empty($start_modifications)) { $start_date = date('Y-m-d', strtotime($start_modifications)); } $sql = "INSERT INTO `" . _DB_PREFIX . "subscription_owner` SET "; $sql .= " owner_id = '" . (int) $owner_id . "'"; $sql .= ", owner_table = '" . mysql_real_escape_string($owner_table) . "'"; $sql .= ", subscription_id = '" . (int) $subscription_id . "'"; $sql .= ", start_date = '{$start_date}'"; query($sql); module_subscription::update_next_due_date($subscription_id, $owner_table, $owner_id, true); // and the same option here to send a subscription straight away upon signup if (module_config::c('subscription_send_invoice_straight_away', 0)) { global $plugins; $plugins['subscription']->run_cron(); // check if there are any invoices for this subscription $history = module_subscription::get_subscription_history($subscription_id, $owner_table, $owner_id); if (count($history) > 0) { foreach ($history as $h) { if ($h['invoice_id']) { $invoice_data = module_invoice::get_invoice($h['invoice_id']); if ($invoice_data['date_cancel'] != '0000-00-00') { continue; } $subscription['subscription_invoice'][] = '<a href="' . module_invoice::link_public($h['invoice_id']) . '">' . _l('Invoice #%s for %s', htmlspecialchars($invoice_data['name']), dollar($invoice_data['total_amount'], true, $invoice_data['currency_id'])) . '</a>'; } } } } } } } } if (!count($subscription['subscription_name'])) { $subscription['subscription_name'][] = _l('N/A'); } if (!count($subscription['subscription_invoice'])) { $subscription['subscription_invoice'][] = _l('N/A'); } $subscription['subscription_name'] = implode(', ', $subscription['subscription_name']); $subscription['subscription_invoice'] = implode(', ', $subscription['subscription_invoice']); // email the admin when a customer signs up. $values = array_merge($customer, $customer_extra, $website, $website_extra, $address, $subscription); $values['customer_name'] = $customer['customer_name']; $values['CUSTOMER_LINK'] = module_customer::link_open($customer_id); $values['CUSTOMER_NAME_LINK'] = module_customer::link_open($customer_id, true); if ($website_id) { $values['WEBSITE_LINK'] = module_website::link_open($website_id); $values['WEBSITE_NAME_LINK'] = module_website::link_open($website_id, true); } else { $values['WEBSITE_LINK'] = _l('N/A'); $values['WEBSITE_NAME_LINK'] = _l('N/A'); } $values['JOB_LINKS'] = ''; if (count($job_created)) { $values['JOB_LINKS'] .= 'The customer created ' . count($job_created) . ' jobs in the system: <br>'; foreach ($job_created as $job_created_id) { $values['JOB_LINKS'] .= module_job::link_open($job_created_id, true) . "<br>\n"; } } else { $values['JOB_LINKS'] = _l('N/A'); } if (count($uploaded_files)) { $values['uploaded_files'] = 'The customer uploaded ' . count($uploaded_files) . " files:<br>\n"; foreach ($uploaded_files as $uploaded_file) { $values['uploaded_files'] .= module_file::link_open($uploaded_file, true) . "<br>\n"; } } else { $values['uploaded_files'] = 'No files were uploaded'; } $values['WEBSITE_NAME'] = isset($website['url']) ? $website['url'] : 'N/A'; if (!$creating_new) { $values['system_note'] = "Note: this signup updated the existing customer record in the system."; } else { $values['system_note'] = "Note: this signup created a new customer record in the system."; } $customer_signup_template = module_config::c('customer_signup_email_admin_template', 'customer_signup_email_admin'); if (isset($_REQUEST['customer_signup_email_admin_template'])) { $customer_signup_template = $_REQUEST['customer_signup_email_admin_template']; } if ($customer_signup_template) { $template = module_template::get_template_by_key($customer_signup_template); if ($template->template_id) { $template->assign_values($values); $html = $template->render('html'); $email = module_email::new_email(); $email->replace_values = $values; $email->set_subject($template->description); $email->set_to_manual(module_config::c('customer_signup_admin_email', module_config::c('admin_email_address'))); // do we send images inline? $email->set_html($html); if ($email->send()) { // it worked successfully!! } else { /// log err? } } } $customer_signup_template = module_config::c('customer_signup_email_welcome_template', 'customer_signup_email_welcome'); if (isset($_REQUEST['customer_signup_email_welcome_template'])) { $customer_signup_template = $_REQUEST['customer_signup_email_welcome_template']; } if ($customer_signup_template) { $template = module_template::get_template_by_key($customer_signup_template); if ($template->template_id) { $template->assign_values($values); $html = $template->render('html'); $email = module_email::new_email(); $email->customer_id = $customer_id; $email->replace_values = $values; $email->set_subject($template->description); $email->set_to('user', $customer_data['primary_user_id']); // do we send images inline? $email->set_html($html); if ($email->send()) { // it worked successfully!! } else { /// log err? } } } //todo: optional redirect to url if (isset($_REQUEST['via_ajax'])) { echo json_encode(array('success' => 1, 'customer_id' => $customer_id)); exit; } if (module_config::c('customer_signup_redirect', '')) { redirect_browser(module_config::c('customer_signup_redirect', '')); } // load up the thank you template. $template = module_template::get_template_by_key('customer_signup_thank_you_page'); $template->page_title = _l("Customer Signup"); foreach ($values as $key => $val) { if (!is_array($val)) { $values[$key] = htmlspecialchars($val); } } $template->assign_values($values); echo $template->render('pretty_html'); exit; break; } }
$c = 0; $total_total = array(0, 0); $total_received = array(0, 0); $total_unpaid = array(0, 0); $total_members = 0; $total_customers = 0; foreach ($subscription_reports as $subscription_report) { ?> <tr class="<?php echo $c++ % 2 ? "odd" : "even"; ?> "> <td> <?php echo module_subscription::link_open($subscription_report['subscription_id'], true, $subscription_report); ?> </td> <td> <?php $total_total[0] += $subscription_report['total_received_count'] + $subscription_report['total_unpaid_count']; $total_total[1] += $subscription_report['total_received'] + $subscription_report['total_unpaid']; // todo - multicurrency echo $subscription_report['total_received_count'] + $subscription_report['total_unpaid_count']; ?> = <?php echo dollar($subscription_report['total_received'] + $subscription_report['total_unpaid'], true, $subscription_report['currency_id']); ?>
if (count($subscription_owner)) { ob_start(); ?> <table border="0" cellspacing="0" cellpadding="2" class="tableclass tableclass_form tableclass_full"> <tbody> <tr> <td> <?php switch ($subscription_owner['owner_table']) { case 'member': $member_name = module_member::link_open($subscription_owner['owner_id'], true); break; case 'website': $member_name = module_website::link_open($subscription_owner['owner_id'], true); break; case 'customer': $member_name = module_customer::link_open($subscription_owner['owner_id'], true); break; } $subscription_name = module_subscription::link_open($subscription['subscription_id'], true); _e('This is a subscription payment for %s %s on the subscription: %s', $subscription_owner['owner_table'], $member_name, $subscription_name); ?> </td> </tr> </tbody> </table> <?php $fieldset_data = array('heading' => array('title' => _l('%s Subscription', _l(ucwords($subscription_owner['owner_table']))), 'type' => 'h3'), 'elements_before' => ob_get_clean()); echo module_form::generate_fieldset($fieldset_data); } }
// display all the notes which are owned by all the sites we have access to $note_summary_owners['job'] = array(); $note_summary_owners['invoice'] = array(); if (class_exists('module_job', false) && module_job::is_plugin_enabled()) { foreach (module_job::get_jobs(array('website_id' => $website_id)) as $val) { $note_summary_owners['job'][] = $val['job_id']; foreach (module_invoice::get_invoices(array('job_id' => $val['job_id'])) as $val2) { $note_summary_owners['invoice'][$val2['invoice_id']] = $val2['invoice_id']; } } } // now find any subscription invoices that are linked to this website. if (class_exists('module_subscription', false)) { $members_subscriptions = module_subscription::get_subscriptions_by('website', $website_id); foreach ($members_subscriptions as $subscription_id => $subscription_info) { $history = module_subscription::get_subscription_history($subscription_id, 'website', $website_id); foreach ($history as $h) { if (is_array($h) && isset($h['invoice_id']) && $h['invoice_id']) { $note_summary_owners['invoice'][$h['invoice_id']] = $h['invoice_id']; } } } } module_note::display_notes(array('title' => module_config::c('project_name_single', 'Website') . ' Notes', 'owner_table' => 'website', 'owner_id' => $website_id, 'view_link' => module_website::link_open($website_id), 'display_summary' => true, 'summary_owners' => $note_summary_owners)); } if (class_exists('module_quote', false) && module_quote::is_plugin_enabled() && module_quote::can_i('view', 'Quotes')) { // show the jobs linked to this website. $quotes = module_quote::get_quotes(array('website_id' => $website_id)); if (count($quotes) || module_quote::can_i('create', 'Quotes')) { $h = array('type' => 'h3', 'title' => module_config::c('project_name_single', 'Website') . ' Quotes'); if (module_quote::can_i('create', 'Quotes')) {
<textarea id="website[notes]" name="website[notes]" rows="7" cols="25"></textarea> </li> </ol> </fieldset> <?php if (class_exists('module_subscription', false)) { ?> <fieldset> <legend>Subscription Details</legend> <input type="hidden" name="subscription[for]" value="website"> <!-- values here are website or customer --> <ol> <li> <fieldset> <legend>Which of the below subscriptions would you like?</legend> <?php $sorted_subscriptions = module_subscription::get_subscriptions(); foreach ($sorted_subscriptions as $subscription) { ?> <label for="subscription_<?php echo $subscription['subscription_id']; ?> "> <input type="checkbox" name="subscription[subscriptions][<?php echo $subscription['subscription_id']; ?> ]" value="1" id="subscription_<?php echo $subscription['subscription_id']; ?> "> <?php echo htmlspecialchars($subscription['name']);
public static function is_automatic_paying_invoice($invoice_id) { $invoice_payments = module_invoice::get_invoice_payments($invoice_id); foreach ($invoice_payments as $payment) { if (isset($payment['invoice_payment_subscription_id']) && $payment['invoice_payment_subscription_id']) { return true; } } // check if this is part of a subscription, and if the previous subscription if (class_exists('module_subscription', false)) { // THIS CODE EXISTS // check if this invoice is part of a subscription. // if it is we hunt through the subscription history until we find a recent unpaid invoice $subscription_history_item = get_single('subscription_history', 'invoice_id', $invoice_id); if ($subscription_history_item && $subscription_history_item['subscription_owner_id']) { // we have an invoice that is on a subscription! $subscription_owner = module_subscription::get_subscription_owner($subscription_history_item['subscription_owner_id']); // check if there are unpaid invoices that were generated after this invoice. if ($subscription_owner['subscription_owner_id'] == $subscription_history_item['subscription_owner_id']) { $subscription_history = get_multiple('subscription_history', array('subscription_owner_id' => $subscription_owner['subscription_owner_id'])); foreach ($subscription_history as $h) { $invoice_payments = module_invoice::get_invoice_payments($h['invoice_id']); foreach ($invoice_payments as $payment) { if (isset($payment['invoice_payment_subscription_id']) && $payment['invoice_payment_subscription_id']) { $payment_subscription = get_single('invoice_payment_subscription', 'invoice_payment_subscription_id', $payment['invoice_payment_subscription_id']); if ($payment_subscription && $payment_subscription['status'] == _INVOICE_SUBSCRIPTION_ACTIVE) { //} || $payment_subscription['status'] == _INVOICE_SUBSCRIPTION_PENDING)){ return true; } } } } } } } return false; }
}, 'cell_class' => 'row_action'); $columns['member_business'] = array('title' => 'Business', 'callback' => function ($member) { echo htmlspecialchars($member['business']); }); $columns['member_phone'] = array('title' => 'Phone', 'callback' => function ($member) { echo htmlspecialchars($member['phone']); }); $columns['member_mobile'] = array('title' => 'Mobile', 'callback' => function ($member) { echo htmlspecialchars($member['mobile']); }); $columns['member_email'] = array('title' => 'Email Address', 'callback' => function ($member) { echo htmlspecialchars($member['email']); }); if (class_exists('module_subscription', false)) { $columns['member_subscription'] = array('title' => 'Subscription', 'callback' => function ($member) { foreach (module_subscription::get_subscriptions_by('member', $member['member_id']) as $subscription) { echo dollar($subscription['amount'], true, $subscription['currency_id']); echo ' '; echo htmlspecialchars($subscription['name']); echo ' '; $next_due = strtotime($subscription['next_due_date']); if ($next_due < time()) { echo ' <span class="important">'; echo _e('Overdue: '); echo '</span> '; } else { _e('Due: '); } echo print_date($next_due); $days = ceil(($next_due - time()) / 86400); if (abs($days) == 0) {
</th> </tr> </thead> <tbody> <?php $c = 0; foreach ($pagination['rows'] as $subscription) { ?> <tr class="<?php echo $c++ % 2 ? "odd" : "even"; ?> "> <td class="row_action"> <?php echo module_subscription::link_open($subscription['subscription_id'], true, $subscription); ?> </td> <td> <?php if (!$subscription['days'] && !$subscription['months'] && !$subscription['years']) { echo _l('Once off'); } else { $bits = array(); if ($subscription['days'] > 0) { $bits[] = _l('%s days', $subscription['days']); } if ($subscription['months'] > 0) { $bits[] = _l('%s months', $subscription['months']); }
public function print_table() { $this->process_data(); if ($this->pagination && isset($this->rows['summary']) && (!$this->pagination_hide_single_page || $this->pagination_hide_single_page && $this->rows['page_numbers'] > 1)) { echo $this->rows['summary']; } $colspan = 0; $this->print_table_before(); ?> <table class="<?php echo $this->table_class; ?> "<?php echo $this->table_id ? ' id="' . $this->table_id . '"' : ''; ?> > <thead> <tr class="title"> <?php foreach ($this->columns as $column_id => $column_data) { $title = is_array($column_data) ? $column_data['title'] : $column_data; $colspan++; ?> <th id="<?php echo $column_id; ?> "><?php echo _l($title); ?> </th> <?php } if (class_exists('module_extra', false) && count($this->extra_fields)) { foreach ($this->extra_fields as $extra_field) { $colspan += module_extra::print_table_header($extra_field['type']); } } if (class_exists('module_subscription', false) && count($this->subscription_fields)) { foreach ($this->subscription_fields as $extra_field) { module_subscription::print_table_header($extra_field['type']); $colspan++; } } ?> </tr> </thead> <?php if (count($this->header_rows)) { ?> <thead class="summary"> <?php foreach ($this->header_rows as $row) { $this->print_footer_row($row); } ?> </thead> <?php } ?> <tbody> <?php $c = 0; if (!count($this->rows['rows'])) { if ($this->blank_message) { ?> <tr> <td colspan="<?php echo $colspan; ?> " class="blank_message" style="text-align: center"><?php _e($this->blank_message); ?> </td> </tr> <?php } } else { foreach ($this->rows['rows'] as $row) { $this->print_row($row); } } ?> </tbody> <?php if (count($this->footer_rows)) { ?> <tfoot class="summary"> <?php foreach ($this->footer_rows as $row) { $this->print_footer_row($row); } ?> </tfoot> <?php } ?> </table> <?php $this->print_table_after(); if ($this->pagination && isset($this->rows['links']) && (!$this->pagination_hide_single_page || $this->pagination_hide_single_page && $this->rows['page_numbers'] > 1)) { echo $this->rows['links']; } }