Beispiel #1
0
 public function Action()
 {
     if (empty($_POST['start_date'])) {
         return null;
     }
     $db = JFactory::getDBO();
     $start_timeframe = $_POST['start_date'] . ' 00:00:00';
     if (!empty($_POST['end_date'])) {
         $end_timeframe = $_POST['end_date'] . ' 23:59:59';
     } else {
         $end_timeframe = date('Y-m-d', (int) gmdate('U'));
     }
     $query = 'SELECT `id`' . ' FROM #__acctexp_log_history' . ' WHERE transaction_date >= \'' . $start_timeframe . '\'' . ' AND transaction_date <= \'' . $end_timeframe . '\'' . ' ORDER BY transaction_date ASC';
     $db->setQuery($query);
     $entries = xJ::getDBArray($db);
     if (empty($entries)) {
         return "nothing to list";
     }
     $historylist = array();
     $groups = array();
     foreach ($entries as $id) {
         $entry = new logHistory($db);
         $entry->load($id);
         $refund = false;
         if (is_array($entry->response)) {
             $filter = array('subscr_signup', 'paymentreview', 'subscr_eot', 'subscr_failed', 'subscr_cancel');
             $refund = false;
             foreach ($entry->response as $v) {
                 if (in_array($v, $filter)) {
                     continue 2;
                 } elseif ($v == 'refund') {
                     $refund = true;
                 }
             }
         }
         $date = date('Y-m-d', strtotime($entry->transaction_date));
         $iFactory = new InvoiceFactory($entry->user_id, null, null, null, null, null, false, true);
         if ($iFactory->userid != $entry->user_id) {
             continue;
         }
         $iFactory->loadMetaUser();
         $iFactory->touchInvoice($entry->invoice_number, false, true);
         if ($iFactory->invoice_number != $entry->invoice_number) {
             continue;
         }
         $iFactory->puffer();
         $iFactory->loadItems();
         $iFactory->loadItemTotal();
         if (isset($iFactory->items->total)) {
             $amount = $iFactory->items->total->cost['amount'];
         } else {
             continue;
         }
         $tax = 0;
         foreach ($iFactory->items->tax as $item) {
             $tax += $item['cost'];
         }
         if ($refund) {
             $historylist[$date]['amount'] -= $amount;
             if ($tax) {
                 $historylist[$date]['taxed'] -= $amount;
                 $historylist[$date]['tax'] -= $tax;
             } else {
                 $historylist[$date]['untaxed'] -= $amount;
             }
         } else {
             $historylist[$date]['amount'] += $amount;
             if ($tax) {
                 $historylist[$date]['taxed'] += $amount;
                 $historylist[$date]['tax'] += $tax;
             } else {
                 $historylist[$date]['untaxed'] += $amount;
             }
         }
     }
     $return = "";
     $return .= '<table style="background-color: fff; width: 30%; margin: 0 auto; text-align: center !important; font-size: 180%;">';
     $i = 0;
     foreach ($historylist as $date => $history) {
         $i++;
         if (date('j', strtotime($date)) == 1 || $i === 1) {
             $month = array();
         }
         $return .= '<tr style="border-bottom: 2px solid #999 !important; height: 2em;">';
         $return .= '<td title="Date" style="text-align: left !important; color: #aaa;">' . $date . '</td>';
         $return .= '<td style="width: 5em;">&nbsp;</td>';
         $return .= '<td title="Non-Taxed" style="font-weight: bold; width: 5em;">' . AECToolbox::correctAmount($history['untaxed']) . '</td>';
         if (!empty($history['taxed'])) {
             $return .= '<td style="width: 5em;">+</td>';
             $return .= '<td title="Taxed including Tax" style="font-weight: bold; width: 5em;">' . AECToolbox::correctAmount($history['taxed'] + $history['tax']) . '</td>';
             $return .= '<td title="Taxed" style="font-weight: bold; width: 5em; color: #aaa;">(' . AECToolbox::correctAmount($history['taxed']) . '</td>';
             $return .= '<td style="width: 5em; color: #aaa;">+</td>';
             $return .= '<td title="Tax" style="font-weight: bold; width: 5em; color: #aaa;">' . AECToolbox::correctAmount($history['tax']) . ')</td>';
         } else {
             $return .= '<td colspan="5"></td>';
         }
         $return .= '<td style="width: 5em;">=</td>';
         $return .= '<td style="width: 5em;">&nbsp;</td>';
         $return .= '<td title="Grand Total" style="text-align: right !important; color: #608919;">' . AECToolbox::correctAmount($history['amount'] + $history['tax']) . '</td>';
         $return .= '</tr>';
         $return .= '<tr style="height: 1px; background-color: #999;">';
         $return .= '<td colspan="11"></td>';
         $return .= '</tr>';
         if (isset($month)) {
             $month['amount'] += $history['amount'];
             $month['tax'] += $history['tax'];
             $month['taxed'] += $history['taxed'];
             $month['untaxed'] += $history['untaxed'];
         }
         if (isset($month) && (date('j', strtotime($date)) == date('t', strtotime($date)) || $i == count($historylist))) {
             $return .= '<tr style="border-bottom: 2px solid #999 !important; height: 2em; background-color: #ddd;">';
             $return .= '<td title="Date" style="text-align: left !important; color: #aaa;">Month</td>';
             $return .= '<td style="width: 5em;">&nbsp;</td>';
             $return .= '<td title="Non-Taxed" style="font-weight: bold; width: 5em;">' . AECToolbox::correctAmount($month['untaxed']) . '</td>';
             if (!empty($month['taxed'])) {
                 $return .= '<td style="width: 5em;">+</td>';
                 $return .= '<td title="Taxed including Tax" style="font-weight: bold; width: 5em;">' . AECToolbox::correctAmount($month['taxed'] + $month['tax']) . '</td>';
                 $return .= '<td title="Taxed" style="font-weight: bold; width: 5em; color: #aaa;">(' . AECToolbox::correctAmount($month['taxed']) . '</td>';
                 $return .= '<td style="width: 5em; color: #aaa;">+</td>';
                 $return .= '<td title="Tax" style="font-weight: bold; width: 5em; color: #aaa;">' . AECToolbox::correctAmount($month['tax']) . ')</td>';
             } else {
                 $return .= '<td colspan="5"></td>';
             }
             $return .= '<td style="width: 5em;">=</td>';
             $return .= '<td style="width: 5em;">&nbsp;</td>';
             $return .= '<td title="Grand Total" style="text-align: right !important; color: #608919;">' . AECToolbox::correctAmount($month['amount'] + $month['tax']) . '</td>';
             $return .= '</tr>';
             $return .= '<tr style="height: 1px; background-color: #999;">';
             $return .= '<td colspan="11"></td>';
             $return .= '</tr>';
         }
     }
     $return .= '</table><br /><br />';
     return $return;
 }
 /**
  * @param Subscription $subscription_id
  */
 public function validateSubscription($subscription_id)
 {
     if (empty($this->settings)) {
         $this->getSettings();
     }
     if (method_exists($this->processor, 'validateSubscription')) {
         $subscription = new Subscription();
         $subscription->load($subscription_id);
         $allowed = array("Trial", "Active");
         if (!in_array($subscription->status, $allowed)) {
             return null;
         }
         $invoice = new Invoice();
         $invoice->loadbySubscriptionId($subscription_id);
         if (empty($invoice->id)) {
             return null;
         }
         $iFactory = new InvoiceFactory(null, null, null, $this->processor_name);
         $iFactory->userid = $subscription->userid;
         $iFactory->usage = $invoice->usage;
         $iFactory->processor = $this->processor_name;
         $iFactory->loadMetaUser();
         $iFactory->touchInvoice($invoice->invoice_number);
         $iFactory->puffer();
         $iFactory->loadItems();
         $iFactory->loadItemTotal();
         foreach ($iFactory->items->itemlist as $item) {
             $this->exchangeSettingsByPlan($item['obj']);
         }
         $result = $this->processor->validateSubscription($iFactory, $subscription);
         $resp = array();
         if (!empty($result['raw'])) {
             if (is_array($result['raw'])) {
                 $resp = $result['raw'];
             } else {
                 $resp['response'] = $result['raw'];
             }
         }
         $iFactory->invoice->processorResponse($iFactory, $result, $resp, true);
         if (!empty($result['valid'])) {
             return true;
         } elseif (empty($result['error'])) {
             return null;
         }
     } else {
         return null;
     }
 }