<?php $orderItem = new MM_OrderItem($p->orderItemId); if ($orderItem->isValid()) { $scheduledPaymentEvent = MM_ScheduledPaymentEvent::findNextScheduledEventByOrderItemId($orderItem->getId(), false); if ($scheduledPaymentEvent->isValid()) { $crntRebillDate = MM_Utils::dateToLocal($scheduledPaymentEvent->getScheduledDate(), "m/d/Y"); ?> <div id='mm-edit-subscription-div'> <input type='hidden' id='order_item_id' value='<?php echo $p->orderItemId; ?> ' /> <a href="#"></a> <p>Next Rebill Date</p> <p style="font-size:11px;"> <input id="mm-next-rebill-date" type="text" style="width: 152px" value="<?php echo $crntRebillDate; ?> " /> <a onClick="jQuery('#mm-next-rebill-date').focus();"><?php echo MM_Utils::getCalendarIcon(); ?> </a> </p> </div> <div class="mm-dialog-footer-container"> <div class="mm-dialog-button-container"> <a href="javascript:mmjs.saveSubscription();" class="mm-ui-button blue">Save</a>
private function temporaryPendingOverdueSubscriptionPatch() { if (class_exists("MM_OrderItem") && $this->hasColumn(MM_TABLE_AUTHNET_ARB_SUBSCRIPTIONS, "id")) { global $wpdb; $pymtServicesTable = MM_TABLE_PAYMENT_SERVICES; $authNetToken = MM_PaymentService::$AUTHORIZENET_SERVICE_TOKEN; $authNetPaymentId = $wpdb->get_var("SELECT id from {$pymtServicesTable} where token='{$authNetToken}'"); if (!is_null($authNetPaymentId)) { $ordersTable = MM_TABLE_ORDERS; $orderItemsTable = MM_TABLE_ORDER_ITEMS; $transactionsTable = MM_TABLE_TRANSACTION_LOG; $transTypePayment = MM_TransactionLog::$TRANSACTION_TYPE_PAYMENT; $transTypeRecurringPayment = MM_TransactionLog::$TRANSACTION_TYPE_RECURRING_PAYMENT; $authNetSubscriptionsTable = MM_TABLE_AUTHNET_ARB_SUBSCRIPTIONS; $orderItemStatusRecurring = MM_OrderItem::$STATUS_RECURRING; $orderItemTypeProduct = MM_OrderItem::$ORDER_ITEM_TYPE_PRODUCT; $sql = "SELECT oi.id as order_item_id, oi.order_id, oi.rebill_period, oi.rebill_frequency, o.user_id FROM {$orderItemsTable} oi INNER JOIN {$ordersTable} o ON (oi.order_id = o.id) LEFT JOIN {$authNetSubscriptionsTable} arbs ON " . "(oi.id = arbs.order_item_id) WHERE o.payment_id='{$authNetPaymentId}' AND oi.status='{$orderItemStatusRecurring}' AND " . "oi.item_type='{$orderItemTypeProduct}' AND oi.is_recurring=1 AND (arbs.x_subscription_id IS NULL)"; $result = $wpdb->get_results($sql); foreach ($result as $row) { // check if pending overdue item has already been inserted for this order item $pendingOverdueSubscriptions = MM_TABLE_AUTHNET_PENDING_OVERDUE_SUBSCRIPTIONS; $pendingOverdueSubscriptionId = $wpdb->get_var("SELECT id from {$pendingOverdueSubscriptions} where order_item_id='{$row->order_item_id}'"); if (is_null($pendingOverdueSubscriptionId)) { // lookup the last transaction associated with the order item $sql = "SELECT transaction_date FROM {$transactionsTable} WHERE order_item_id = {$row->order_item_id} AND "; $sql .= "transaction_type IN ({$transTypePayment}, {$transTypeRecurringPayment}) "; $sql .= "ORDER BY transaction_date DESC LIMIT 1;"; $lastTransaction = $wpdb->get_row($sql); if ($lastTransaction) { // set status of order item to pending overdue $orderItem = new MM_OrderItem($row->order_item_id); if ($orderItem->isValid()) { $orderItem->setStatus(5); // set to pending overdue status, not using constant as this script is being run in the installer // and on first run the constant may not be defined $orderItem->commitData(); // calculate overdue date based on last transaction date and length of subscription cycle $overdueDate = date('Y-m-d', strtotime($lastTransaction->transaction_date . ' +' . $row->rebill_period . ' ' . $row->rebill_frequency)); $insertData = array("order_item_id" => $row->order_item_id, "overdue_date" => $overdueDate); $wpdb->insert(MM_TABLE_AUTHNET_PENDING_OVERDUE_SUBSCRIPTIONS, $insertData); } } } } } } }