コード例 #1
0
ファイル: tool_rebuildrebills.php プロジェクト: Ibrahim1/aec
 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)";
         }
     }
 }
コード例 #2
0
ファイル: tool_pretend.php プロジェクト: Ibrahim1/aec
 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();
 }