Example #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($end)) {
         $end = date('Y-m-d', (int) gmdate('U'));
     }
     $end_timeframe = $end . ' 23:59:59';
     $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();
         $entry->load($id);
         $refund = false;
         if (is_array($entry->response)) {
             $filter = array('new_case', 'subscr_signup', 'paymentreview', 'subscr_eot', 'subscr_failed', 'subscr_cancel', 'Pending', 'Denied');
             $refund = false;
             foreach ($entry->response as $v) {
                 if (in_array($v, $filter)) {
                     continue 2;
                 } elseif ($v == 'refund' || $v == 'Reversed' || $v == 'Refunded') {
                     $refund = true;
                 }
             }
         }
         $date = date('Y-m-d', strtotime($entry->transaction_date));
         $pgroups = ItemGroupHandler::parentGroups($entry->plan_id);
         if (!in_array($pgroups[0], $groups)) {
             $groups[] = $pgroups[0];
         }
         if (!isset($historylist[$date])) {
             $historylist[$date] = array('amount' => null, 'groups' => null);
         }
         if ($refund) {
             $historylist[$date]['amount'] -= (double) $entry->amount;
             $historylist[$date]['groups'][$pgroups[0]]--;
         } else {
             $historylist[$date]['amount'] += (double) $entry->amount;
             $historylist[$date]['groups'][$pgroups[0]]++;
         }
     }
     foreach ($historylist as $date => $entry) {
         ksort($historylist[$date]['groups']);
     }
     $return = "";
     $return .= '<table style="background-color: fff; width: 30%; margin: 0 auto; text-align: center !important; font-size: 180%;">';
     $groupnames = array();
     foreach ($groups as $group) {
         $groupnames[$group] = ItemGroupHandler::groupName($group);
     }
     $closer = 0;
     $incomplete = false;
     foreach ($historylist as $date => $history) {
         if (date('D', strtotime($date)) == 'Mon') {
             $week = array();
         } elseif (!isset($week)) {
             $week = array();
             $incomplete = true;
         }
         $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>';
         foreach ($groups as $group) {
             if (empty($history['groups'][$group])) {
                 $count = 0;
             } else {
                 $count = $history['groups'][$group];
             }
             $return .= '<td title="' . $groupnames[$group] . '" style="font-weight: bold; width: 5em;">' . $count . '</td>';
             if (isset($week)) {
                 $week['groups'][$group] += $count;
             }
         }
         if (isset($week)) {
             $week['amount'] += $history['amount'];
         }
         $return .= '<td style="width: 5em;">&nbsp;</td>';
         $return .= '<td title="Amount" style="text-align: right !important; color: #608919;">' . AECToolbox::correctAmount($history['amount']) . '</td>';
         $return .= '</tr>';
         $return .= '<tr style="height: 1px; background-color: #999;">';
         $return .= '<td colspan="' . (count($groups) + 4) . '"></td>';
         $return .= '</tr>';
         $closer = 0;
         if (date('D', strtotime($date)) == 'Sun') {
             $return .= '<tr ' . ($incomplete ? 'title="Incomplete!"' : '') . 'style="border-bottom: 2px solid #999 !important; height: 2em; background-color: #ddd;">';
             $return .= '<td style="text-align: left !important; color: #aaa;">' . ($incomplete ? '(Week)' : 'Week') . '</td>';
             $return .= '<td style="width: 5em;">&nbsp;</td>';
             foreach ($groups as $group) {
                 if (empty($week['groups'][$group])) {
                     $count = 0;
                 } else {
                     $count = $week['groups'][$group];
                 }
                 if ($incomplete) {
                     $return .= '<td title="' . $groupnames[$group] . '" style="font-weight: bold; width: 5em;">(' . $count . ')</td>';
                 } else {
                     $return .= '<td title="' . $groupnames[$group] . '" style="font-weight: bold; width: 5em;">' . $count . '</td>';
                 }
             }
             $return .= '<td style="width: 5em;">&nbsp;</td>';
             if ($incomplete) {
                 $return .= '<td title="Amount" style="text-align: right !important; color: #608919;">(' . AECToolbox::correctAmount($week['amount']) . ')</td>';
             } else {
                 $return .= '<td title="Amount" style="text-align: right !important; color: #608919;">' . AECToolbox::correctAmount($week['amount']) . '</td>';
             }
             $return .= '</tr>';
             $return .= '<tr style="height: 1px; background-color: #999;">';
             $return .= '<td colspan="' . (count($groups) + 4) . '"></td>';
             $return .= '</tr>';
             $closer = 1;
             $incomplete = false;
         }
     }
     if (!$closer) {
         $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;">(Week)</td>';
         $return .= '<td style="width: 5em;">&nbsp;</td>';
         foreach ($groups as $group) {
             if (empty($week['groups'][$group])) {
                 $count = 0;
             } else {
                 $count = $week['groups'][$group];
             }
             $return .= '<td title="' . $groupnames[$group] . '" style="font-weight: bold; width: 5em;">' . $count . '</td>';
         }
         $return .= '<td style="width: 5em;">&nbsp;</td>';
         $return .= '<td title="Amount" style="text-align: right !important; color: #608919;">' . AECToolbox::correctAmount($week['amount']) . '</td>';
         $return .= '</tr>';
         $return .= '<tr style="height: 1px; background-color: #999;">';
         $return .= '<td colspan="' . (count($groups) + 4) . '"></td>';
         $return .= '</tr>';
         $closer = 1;
     }
     $return .= '</table><br /><br />';
     return $return;
 }
Example #2
0
 public function request($type, $start, $end)
 {
     $tree = new stdClass();
     switch ($type) {
         case 'sales':
             $tree = array();
             if (empty($end)) {
                 $end = date('Y-m-d H:i:s', (int) gmdate('U'));
             }
             $query = 'SELECT `id`' . ' FROM #__acctexp_log_history' . ' WHERE transaction_date >= \'' . $start . '\'' . ' AND transaction_date <= \'' . $end . '\'' . ' ORDER BY transaction_date ASC';
             $this->db->setQuery($query);
             $entries = xJ::getDBArray($this->db);
             if (empty($entries)) {
                 echo json_encode($tree);
                 exit;
             }
             $historylist = array();
             $groups = array();
             foreach ($entries as $id) {
                 $entry = new logHistory();
                 $entry->load($id);
                 $entry->amount = AECToolbox::correctAmount($entry->amount);
                 $refund = false;
                 if (is_array($entry->response) && !empty($entry->response)) {
                     $filter = array('new_case', 'subscr_signup', 'paymentreview', 'subscr_eot', 'subscr_failed', 'subscr_cancel', 'Pending', 'Denied');
                     foreach ($entry->response as $v) {
                         if (in_array($v, $filter)) {
                             continue 2;
                         } elseif ($v == 'refund' || $v == 'Reversed' || $v == 'Refunded') {
                             $refund = true;
                         }
                     }
                 } else {
                     continue;
                 }
                 $pgroups = ItemGroupHandler::parentGroups($entry->plan_id);
                 if (empty($pgroups[0])) {
                     $pgroups[0] = 0;
                 }
                 if (!in_array($pgroups[0], $groups)) {
                     $groups[] = $pgroups[0];
                 }
                 $sale = new stdClass();
                 $sale->id = $id;
                 //$sale->invoice	= $entry->invoice_number;
                 $sale->date = $entry->transaction_date;
                 //$sale->datejs	= date( 'F d, Y H:i:s', strtotime( $entry->transaction_date ) );
                 $sale->plan = $entry->plan_id;
                 $sale->group = $pgroups[0];
                 $sale->amount = $refund ? -$entry->amount : $entry->amount;
                 $tree[] = $sale;
             }
             break;
     }
     echo json_encode($tree);
     exit;
 }
Example #3
0
 public function Action()
 {
     $db = JFactory::getDBO();
     $entries = 0;
     $planlist = array();
     $pplist = array();
     $processors = array('authorize_arb', 'google_checkout', 'hsbc', 'iats', 'paypal_wpp', 'sparkassen_internetkasse', 'usaepay');
     $query = 'SELECT `id`' . ' FROM #__acctexp_invoices' . ' WHERE `method` IN (' . implode(',', $processors) . ')';
     $db->setQuery($query);
     $invoices = xJ::getDBArray($db);
     foreach ($invoices as $id) {
         $invoice = new Invoice();
         $invoice->load($id);
         // Skip non-rebilled
         if (count($invoice->transactions) < 2) {
             continue;
         }
         foreach ($invoice->transactions as $tid => $transaction) {
             if (!$tid) {
                 // Skip first entry
                 continue;
             }
             if (!empty($_POST['safe'])) {
                 $query = 'SELECT `id`' . ' FROM #__acctexp_log_history' . ' WHERE transaction_date = \'' . $transaction->timestamp . '\'' . ' AND proc_name = \'' . $transaction->processor . '\'' . ' AND invoice_number = \'' . $invoice->invoice_number . '\'';
                 $db->setQuery($query);
                 $hasentry = $db->loadResult();
                 if ($hasentry) {
                     continue;
                 }
             }
             $entries++;
             if (!empty($_POST['create'])) {
                 $entry = new logHistory();
                 $user = new cmsUser();
                 $user->load($invoice->userid);
                 if (!isset($planlist[$invoice->usage])) {
                     $plan = new SubscriptionPlan();
                     $plan->load($invoice->usage);
                     $planlist[$invoice->usage] = $plan;
                 }
                 if (!isset($pplist[$invoice->method])) {
                     $pp = new SubscriptionPlan();
                     $pp->load($invoice->method);
                     $pplist[$invoice->method] = $pp;
                 }
                 if ($pplist[$invoice->method]->id) {
                     $entry->proc_id = $pplist[$invoice->method]->id;
                     $entry->proc_name = $pplist[$invoice->method]->processor_name;
                 }
                 $entry->user_id = $user->id;
                 $entry->user_name = $user->username;
                 if ($planlist[$invoice->usage]->id) {
                     $entry->plan_id = $planlist[$invoice->usage]->id;
                     $entry->plan_name = $planlist[$invoice->usage]->name;
                 }
                 $entry->transaction_date = $transaction->timestamp;
                 $entry->amount = $transaction->amount;
                 $entry->invoice_number = $invoice->invoice_number;
                 $entry->response = 'Created by the Rebuild Rebills Tool';
                 $entry->cleanup();
                 $entry->check();
                 $entry->store();
             }
         }
     }
     if (empty($entries)) {
         if ($_POST['create']) {
             return "No Invoices found to create History Entries from.";
         } else {
             return "No Invoices with data found.";
         }
     } else {
         if ($_POST['create']) {
             return $entries . " History Entries created.";
         } else {
             return "No History Entries created, found " . $entries . " that can be converted (select 'Create' from the settings above and carry out the query again)";
         }
     }
 }
Example #4
0
 /**
  * @param InvoiceFactory $InvoiceFactory
  */
 public function processorResponse($InvoiceFactory, $response, $resp = '', $altvalidation = false)
 {
     global $aecConfig;
     if (!is_array($response)) {
         $response = array('original_response' => $response);
     }
     $this->computeAmount($InvoiceFactory);
     $objUsage = $this->getObjUsage();
     if (is_a($objUsage, 'SubscriptionPlan')) {
         $plan = $objUsage;
     } else {
         $plan = $objUsage->getTopPlan();
     }
     $response['planparams'] = $plan->getProcessorParameters($InvoiceFactory->pp);
     $post = aecPostParamClear($_POST);
     $response['userid'] = $this->userid;
     $InvoiceFactory->pp->exchangeSettingsByPlan($plan, $plan->params);
     if ($altvalidation) {
         $response = $InvoiceFactory->pp->instantvalidateNotification($response, $post, $this);
     } else {
         $response = $InvoiceFactory->pp->validateNotification($response, $post, $this);
     }
     if (!empty($aecConfig->cfg['invoice_cushion']) && $this->transaction_date !== '0000-00-00 00:00:00') {
         if (strtotime($this->transaction_date) + $aecConfig->cfg['invoice_cushion'] * 60 > (int) gmdate('U')) {
             if ($InvoiceFactory->pp->processor_name == 'desjardins') {
                 // Desjardins is the only exception so far... bad bad bad
             } elseif ($response['valid']) {
                 // The last notification has not been too long ago - skipping this one
                 // But only skip actual payment notifications - errors are OK
                 $short = JText::_('AEC_MSG_PROC_INVOICE_ACTION_SH');
                 $event = JText::_('AEC_MSG_PROC_INVOICE_ACTION_EV_DUPLICATE') . "\n";
                 $tags = 'invoice,processor,duplicate';
                 $level = 2;
                 $params = array('invoice_number' => $this->invoice_number);
                 $eventlog = new eventLog();
                 $eventlog->issue($short, $tags, $event, $level, $params);
                 return $response;
             }
         }
     }
     if (isset($response['userid'])) {
         unset($response['userid']);
     }
     if (isset($response['planparams'])) {
         unset($response['planparams']);
     }
     if (isset($response['secondary_ident'])) {
         $this->secondary_ident = $response['secondary_ident'];
         $this->storeload();
         unset($response['secondary_ident']);
     }
     if (isset($response['invoiceparams'])) {
         $this->addParams($response['invoiceparams']);
         $this->storeload();
         unset($response['invoiceparams']);
     }
     if (isset($response['multiplicator'])) {
         $multiplicator = $response['multiplicator'];
         unset($response['multiplicator']);
     } else {
         $multiplicator = 1;
     }
     if (isset($response['fullresponse'])) {
         $resp = $response['fullresponse'];
         unset($response['fullresponse']);
     }
     if (empty($resp) && !empty($response['raw'])) {
         $resp = $response['raw'];
     }
     if (isset($response['break_processing'])) {
         unset($response['break_processing']);
         return $response;
     }
     $metaUser = new metaUser($this->userid);
     $mi_event = null;
     // Create history entry
     $history = new logHistory();
     $history->entryFromInvoice($this, $resp, $InvoiceFactory->pp);
     $short = JText::_('AEC_MSG_PROC_INVOICE_ACTION_SH');
     $event = JText::_('AEC_MSG_PROC_INVOICE_ACTION_EV') . "\n";
     if (!empty($response)) {
         foreach ($response as $key => $value) {
             $event .= $key . "=" . $value . "\n";
         }
     }
     $event .= JText::_('AEC_MSG_PROC_INVOICE_ACTION_EV_STATUS');
     $tags = 'invoice,processor';
     $level = 2;
     $params = array('invoice_number' => $this->invoice_number);
     $forcedisplay = false;
     $event .= ' ';
     $notificationerror = null;
     if ($response['valid']) {
         $break = 0;
         // If not in Testmode, check for amount and currency
         if (empty($InvoiceFactory->pp->settings['testmode'])) {
             if (isset($response['amount_paid'])) {
                 // In some cases, a straight up != can still come out as an error, so forcing INT
                 $ampaid = (int) ($response['amount_paid'] * 100);
                 $amasked = (int) ($this->amount * 100);
                 if ($ampaid != $amasked) {
                     // Amount Fraud, cancel payment and create error log addition
                     $event .= sprintf(JText::_('AEC_MSG_PROC_INVOICE_ACTION_EV_FRAUD'), $response['amount_paid'], $this->amount);
                     $tags .= ',fraud_attempt,amount_fraud';
                     $break = 1;
                     $notificationerror = 'Wrong amount for invoice. Amount provided: "' . $response['amount_paid'] . '"';
                 }
             }
             if (isset($response['amount_currency'])) {
                 if ($response['amount_currency'] != $this->currency) {
                     // Amount Fraud, cancel payment and create error log addition
                     $event .= sprintf(JText::_('AEC_MSG_PROC_INVOICE_ACTION_EV_CURR'), $response['amount_currency'], $this->currency);
                     $tags .= ',fraud_attempt,currency_fraud';
                     $break = 1;
                     $notificationerror = 'Wrong currency for invoice. Currency provided: "' . $response['amount_currency'] . '"';
                 }
             }
         }
         if (!$break) {
             if ($this->pay($multiplicator) === false) {
                 $notificationerror = 'Item Application failed. Please contact the System Administrator';
                 // Something went wrong
                 $event .= JText::_('AEC_MSG_PROC_INVOICE_ACTION_EV_VALID_APPFAIL');
                 $tags .= ',payment,action_failed';
             } else {
                 $event .= JText::_('AEC_MSG_PROC_INVOICE_ACTION_EV_VALID');
                 $tags .= ',payment,action';
             }
         } else {
             $level = 128;
         }
     } else {
         if (isset($response['pending'])) {
             if (strcmp($response['pending_reason'], 'signup') === 0) {
                 if ($plan->params['trial_free'] || $this->amount == '0.00') {
                     $this->pay($multiplicator);
                     $this->addParams(array('free_trial' => $response['pending_reason']), 'params', true);
                     $event .= JText::_('AEC_MSG_PROC_INVOICE_ACTION_EV_TRIAL');
                     $tags .= ',payment,action,trial';
                 }
             } else {
                 $this->addParams(array('pending_reason' => $response['pending_reason']), 'params', true);
                 $event .= sprintf(JText::_('AEC_MSG_PROC_INVOICE_ACTION_EV_PEND'), $response['pending_reason']);
                 $tags .= ',payment,pending' . $response['pending_reason'];
                 $mi_event = '_payment_pending';
             }
             $this->storeload();
         } elseif (isset($response['cancel'])) {
             $mi_event = '_payment_cancel';
             $event .= JText::_('AEC_MSG_PROC_INVOICE_ACTION_EV_CANCEL');
             $tags .= ',cancel';
             if ($metaUser->hasSubscription) {
                 if (!empty($this->subscr_id)) {
                     $metaUser->moveFocus($this->subscr_id);
                 }
                 if (isset($response['cancel_expire'])) {
                     $mi_event = '_payment_cancel_expire';
                     $metaUser->focusSubscription->expire();
                     $tags .= ',expire';
                 } else {
                     $metaUser->focusSubscription->cancel($this);
                 }
                 $event .= JText::_('AEC_MSG_PROC_INVOICE_ACTION_EV_USTATUS');
             }
         } elseif (isset($response['chargeback'])) {
             $mi_event = '_payment_chargeback';
             $event .= JText::_('AEC_MSG_PROC_INVOICE_ACTION_EV_CHARGEBACK');
             $tags .= ',chargeback';
             $level = 128;
             if ($metaUser->hasSubscription) {
                 if (!empty($this->subscr_id)) {
                     $metaUser->moveFocus($this->subscr_id);
                 }
                 $metaUser->focusSubscription->hold($this);
                 $event .= JText::_('AEC_MSG_PROC_INVOICE_ACTION_EV_USTATUS_HOLD');
             }
         } elseif (isset($response['chargeback_settle'])) {
             $mi_event = '_payment_chargeback_settle';
             $event .= JText::_('AEC_MSG_PROC_INVOICE_ACTION_EV_CHARGEBACK_SETTLE');
             $tags .= ',chargeback_settle';
             $level = 8;
             $forcedisplay = true;
             if ($metaUser->hasSubscription) {
                 if (!empty($this->subscr_id)) {
                     $metaUser->moveFocus($this->subscr_id);
                 }
                 $metaUser->focusSubscription->hold_settle($this);
                 $event .= JText::_('AEC_MSG_PROC_INVOICE_ACTION_EV_USTATUS_ACTIVE');
             }
         } elseif (isset($response['delete'])) {
             $mi_event = '_payment_refund';
             $event .= JText::_('AEC_MSG_PROC_INVOICE_ACTION_EV_REFUND');
             $tags .= ',refund';
             if ($metaUser->hasSubscription) {
                 if (!empty($this->subscr_id)) {
                     $metaUser->moveFocus($this->subscr_id);
                 }
                 $usage = $this->getObjUsage();
                 if (is_a($usage, 'SubscriptionPlan')) {
                     // Check whether we're really expiring the right membership,
                     // Maybe the user was already switched to a different plan
                     if ($metaUser->focusSubscription->plan == $usage->id) {
                         $metaUser->focusSubscription->expire(false, 'refund');
                         $event .= JText::_('AEC_MSG_PROC_INVOICE_ACTION_EV_EXPIRED');
                     }
                 } else {
                     $metaUser->focusSubscription->expire(false, 'refund');
                     $event .= JText::_('AEC_MSG_PROC_INVOICE_ACTION_EV_EXPIRED');
                 }
             }
         } elseif (isset($response['eot'])) {
             $mi_event = '_payment_eot';
             $event .= JText::_('AEC_MSG_PROC_INVOICE_ACTION_EV_EOT');
             $tags .= ',eot';
         } elseif (isset($response['duplicate'])) {
             $mi_event = '_payment_duplicate';
             $event .= JText::_('AEC_MSG_PROC_INVOICE_ACTION_EV_DUPLICATE');
             $tags .= ',duplicate';
         } elseif (isset($response['null'])) {
             $mi_event = '_payment_null';
             $event .= JText::_('AEC_MSG_PROC_INVOICE_ACTION_EV_NULL');
             $tags .= ',null';
         } elseif (isset($response['error']) && isset($response['errormsg'])) {
             $mi_event = '_payment_error';
             $event .= 'Error:' . $response['errormsg'];
             $tags .= ',error';
             $level = 128;
             $notificationerror = $response['errormsg'];
         } else {
             $event .= JText::_('AEC_MSG_PROC_INVOICE_ACTION_EV_U_ERROR');
             $tags .= ',general_error';
             $level = 128;
             $notificationerror = 'General Error. Please contact the System Administrator.';
         }
     }
     if (!empty($mi_event) && !empty($this->usage)) {
         $objUsage = new SubscriptionPlan();
         $objUsage->load($this->usage);
         $exchange = $silent = null;
         $objUsage->triggerMIs($mi_event, $metaUser, $exchange, $this, $response, $silent);
     }
     if (isset($response['explanation'])) {
         $event .= " (" . $response['explanation'] . ")";
     }
     $eventlog = new eventLog();
     $eventlog->issue($short, $tags, $event, $level, $params, $forcedisplay);
     if (!empty($notificationerror)) {
         $InvoiceFactory->pp->notificationError($response, $notificationerror);
     } else {
         $InvoiceFactory->pp->notificationSuccess($response);
     }
     return $response;
 }
Example #5
0
 public function createPayments()
 {
     if (!$_POST['create_payments']) {
         return;
     }
     $db = JFactory::getDBO();
     $amountlist = array();
     for ($i = $this->range['plans']['start']; $i <= $this->range['plans']['end']; $i++) {
         $amountlist[$i] = array();
         $modlist[$i]['sin'] = rand(0, 360);
         $modlist[$i]['speed'] = rand(0, 1000) / 100;
         $modlist[$i]['multi'] = rand(0, 100) / 50;
     }
     $start_date = strtotime($_POST['start'] . '-01-01 00:00:00');
     $years = (int) date('Y') - $_POST['start'];
     $days = $years * 365 + date('z') + 1;
     $saleslist = $this->stream_layers($amountlist, $days + 2, 1);
     $plandetails = array();
     $query = 'SELECT MIN(id)' . ' FROM #__acctexp_log_history';
     $db->setQuery($query);
     $this->range['payments']['start'] = $db->loadResult() + 1;
     for ($i = 1; $i <= $days; $i++) {
         $dtime = strtotime("+" . $i . " days", $start_date);
         foreach ($modlist as $k => $v) {
             $modlist[$k]['sin'] += $modlist[$k]['speed'];
             $modlist[$k]['sin'] = $modlist[$k] % 360;
         }
         foreach ($saleslist as $plan => $dayslist) {
             if (!isset($plandetails[$plan])) {
                 $splan = new SubscriptionPlan();
                 $splan->load($plan);
                 $plandetails[$plan] = array('name' => $splan->name, 'cost' => $splan->params['full_amount']);
             }
             // Add some sine modification
             $dsales = (int) ($dayslist[$i] * ((1 + sin($modlist[$plan]['sin'])) * $modlist[$plan]['multi']));
             // Less sales on the weekends
             if (date('N', $dtime) > 5) {
                 $dsales = (int) ($dsales / rand(1, 4));
             }
             for ($j = 0; $j < $dsales; $j++) {
                 $found = false;
                 while (!$found) {
                     $userid = rand($this->range['users']['start'], $this->range['users']['end']);
                     $db->setQuery('SELECT id FROM #__users WHERE `id` = \'' . $userid . '\'');
                     $check = $db->loadResult();
                     $found = !empty($check);
                 }
                 $invoice = new Invoice();
                 $invoice->userid = $userid;
                 $invoice->usage = $plan;
                 $invoice->method = 'none';
                 $invoice->invoice_number = $invoice->generateInvoiceNumber();
                 $invoice->storeload();
                 $invoice->computeAmount();
                 $invoice->pay();
                 $invoice->transaction_date = date('Y-m-d H:i:s', $dtime + rand(0, 86400));
                 $invoice->check();
                 $invoice->store();
                 $pp = new stdClass();
                 $pp->id = 0;
                 $pp->processor_name = 'none';
                 $history = new logHistory();
                 $history->entryFromInvoice($invoice, array("dummy" => "data"), $pp);
                 $history->transaction_date = date('Y-m-d H:i:s', $dtime + rand(0, 86400));
                 $history->check();
                 $history->store();
             }
         }
     }
     $query = 'SELECT MAX(id)' . ' FROM #__acctexp_log_history';
     $db->setQuery($query);
     $this->range['payments']['end'] = $db->loadResult();
 }
Example #6
0
 public function exportSales()
 {
     $db = JFactory::getDBO();
     $query = 'SELECT `id`' . ' FROM #__acctexp_log_history' . ' WHERE transaction_date >= \'' . $this->filter['date_start'] . '\'' . ' AND transaction_date <= \'' . $this->filter['date_end'] . '\'' . ' ORDER BY transaction_date ASC';
     $db->setQuery($query);
     $entries = xJ::getDBArray($db);
     switch ($this->options['collate']) {
         default:
         case 'day':
             $collation = 'Y-m-d';
             break;
         case 'week':
             $collation = 'Y-W';
             break;
         case 'month':
             $collation = 'Y-m';
             break;
         case 'year':
             $collation = 'Y';
             break;
     }
     $collators = array();
     switch ($this->options['breakdown']) {
         default:
         case 'plan':
             break;
         case 'group':
             $all_groups = ItemGroupHandler::getGroups();
             $collators = array();
             foreach ($all_groups as $gid) {
                 $collators[$gid] = ItemGroupHandler::getChildren($gid, 'item');
             }
             break;
     }
     $historylist = array();
     foreach ($entries as $id) {
         $entry = new logHistory();
         $entry->load($id);
         if (empty($entry->plan_id) || empty($entry->amount)) {
             continue;
         }
         if (!empty($this->filter['groupid'])) {
             if (empty($this->filter['planid'])) {
                 $this->filter['planid'] = array();
             }
             $children = ItemGroupHandler::getChildren($this->filter['groupid'], 'item');
             if (!empty($children)) {
                 $this->filter['planid'] = array_merge($this->filter['planid'], $children);
                 $this->filter['planid'] = array_unique($this->filter['planid']);
             }
         }
         if (!empty($this->filter['planid'])) {
             if (!in_array($entry->plan_id, $this->filter['planid'])) {
                 continue;
             }
         }
         if (!empty($this->filter['method'])) {
             if (!in_array($entry->proc_id, $this->filter['method'])) {
                 continue;
             }
         }
         $refund = false;
         if (is_array($entry->response)) {
             $filter = array('new_case', 'subscr_signup', 'paymentreview', 'subscr_eot', 'subscr_failed', 'subscr_cancel', 'Pending', 'Denied');
             $refund = false;
             foreach ($entry->response as $v) {
                 if (in_array($v, $filter)) {
                     continue 2;
                 } elseif ($v == 'refund' || $v == 'Reversed' || $v == 'Refunded') {
                     $refund = true;
                 }
             }
         }
         $date = date($collation, strtotime($entry->transaction_date));
         if ($this->options['breakdown'] == 'plan') {
             if (!array_key_exists($entry->plan_id, $collators)) {
                 $collators[$entry->plan_id] = 0;
             }
         }
         if (!isset($historylist[$date])) {
             $historylist[$date] = array();
         }
         $historylist[$date][] = $entry;
     }
     $line = array("line" => "Date");
     if ($this->options['breakdown'] == 'plan') {
         foreach ($collators as $col => $colamount) {
             $line['plan-' . $col] = "Plan #{$col}: " . SubscriptionPlanHandler::planName($col);
         }
     } elseif ($this->options['breakdown'] == 'group') {
         foreach ($collators as $col => $colplans) {
             $line['group-' . $col] = "Group #{$col}:" . ItemGroupHandler::groupName($col);
         }
     }
     $line['total_sum'] = "Total";
     // Remove whitespaces and newlines
     foreach ($line as $larrid => $larrval) {
         $line[$larrid] = trim($larrval);
         if (is_numeric($larrval)) {
             $line[$larrid] = AECToolbox::correctAmount($larrval);
         }
     }
     $this->exphandler->putDescription($line);
     $totalsum = 0;
     $collate_all = array();
     foreach ($collators as $col => $colv) {
         $collate_all[$col] = 0;
     }
     foreach ($historylist as $date => $collater) {
         $linesum = 0;
         $collatex = array();
         foreach ($collators as $col => $colv) {
             $collatex[$col] = 0;
         }
         foreach ($collater as $entry) {
             if ($this->options['breakdown'] == 'plan') {
                 $collatex[$entry->plan_id] += $entry->amount;
                 $collate_all[$entry->plan_id] += $entry->amount;
                 $linesum += $entry->amount;
                 $totalsum += $entry->amount;
             } else {
                 $pgroup = 0;
                 foreach ($collators as $gid => $gplans) {
                     if ($entry->plan_id == $gid) {
                         $pgroup = $gid;
                         break;
                     }
                 }
                 if ($pgroup) {
                     $collatex[$pgroup] += $entry->amount;
                     $collate_all[$pgroup] += $entry->amount;
                 }
                 $linesum += $entry->amount;
                 $totalsum += $entry->amount;
             }
         }
         $line = array("date" => $date);
         foreach ($collators as $col => $colamount) {
             if ($this->options['breakdown'] == 'plan') {
                 $line['plan-' . $col] = $collatex[$col];
             } else {
                 $line['group-' . $col] = $collatex[$col];
             }
         }
         $line['total_sum'] = $linesum;
         // Remove whitespaces and newlines
         $i = 0;
         foreach ($line as $larrid => $larrval) {
             $line[$larrid] = trim($larrval);
             if (is_numeric($larrval) && $i) {
                 $line[$larrid] = AECToolbox::correctAmount($larrval);
             }
             $i++;
         }
         $this->exphandler->putln($line);
     }
     $line = array("line" => "Grand Total");
     foreach ($collate_all as $col => $colamount) {
         if ($this->options['breakdown'] == 'plan') {
             $line['plan-' . $col] = $colamount;
         } else {
             $line['group-' . $col] = $colamount;
         }
     }
     $line['total_sum'] = $totalsum;
     // Remove whitespaces and newlines
     foreach ($line as $larrid => $larrval) {
         $line[$larrid] = trim($larrval);
         if (is_numeric($larrval)) {
             $line[$larrid] = AECToolbox::correctAmount($larrval);
         }
     }
     $this->exphandler->putSum($line);
 }
Example #7
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;
 }
Example #8
0
// Making up for old thoughts
$db->setQuery("UPDATE #__acctexp_itemxgroup SET group_id='1' WHERE group_id='0'");
$db->query();
// Fixing secondary invoice numbers for CCBill
$query = 'SELECT id FROM #__acctexp_config_processors WHERE name = \'ccbill\'';
$db->setQuery($query);
$ccid = $db->loadResult();
// Checking whether CCBill is installed at all
if ($ccid) {
    // Get all history entries for CCBill
    $query = 'SELECT id FROM #__acctexp_log_history WHERE proc_id = \'' . $ccid . '\'';
    $db->setQuery($query);
    $list = xJ::getDBArray($db);
    if (!empty($list)) {
        foreach ($list as $hid) {
            $history = new logHistory();
            $history->load($hid);
            $params = parameterHandler::decode(stripslashes($history->response));
            // Check for the parameters we need
            if (isset($params['subscription_id']) && isset($params['invoice'])) {
                $query = 'UPDATE #__acctexp_invoices SET `secondary_ident` = \'' . $params['subscription_id'] . '\' WHERE invoice_number = \'' . $params['invoice'] . '\'';
                $db->setQuery($query);
                $db->query();
            }
        }
    }
}
// Haunted by ghosts of xmas past
$query = 'SELECT `id` FROM #__acctexp_subscr WHERE `params` LIKE \'%_jsoon%\'';
$db->setQuery($query);
$list = xJ::getDBArray($db);