/** * Return a Wallet Journal for a Corporation * * @param int $corporation_id * @param bool $get * @param int $chunk * * @return \Illuminate\Pagination\LengthAwarePaginator */ public function getCorporationWalletJournal(int $corporation_id, bool $get = true, int $chunk = 50) { $journal = WalletJournal::leftJoin('eve_ref_types', function ($join) { $join->on('corporation_wallet_journals.refTypeID', '=', 'eve_ref_types.refTypeID'); })->where('corporationID', $corporation_id); if ($get) { return $journal->orderBy('date', 'desc')->paginate($chunk); } return $journal; }
/** * Run the Update * * @return mixed|void */ public function call() { $pheal = $this->setScope('corp')->setCorporationID()->getPheal(); $account_ids = AccountBalanceModel::where('corporationID', $this->corporationID)->pluck('accountKey'); foreach ($account_ids as $account_id) { // Define the first MAX from_id to use when // retreiving transactions. $from_id = PHP_INT_MAX; // Set the transaction overlap marker. This will // be checked after processing an API response to // see if any of the transactions we got back was // already known. $transaction_overlap = false; // This infinite loop needs to be broken out of // once we have reached the end of the backwards // journal walking. Walking ends when we have // either received less rows than asked for, or // we have reached a known transaction hash. while (true) { $result = $pheal->WalletJournal(['accountKey' => $account_id, 'rowCount' => $this->rows_per_call] + ($from_id == PHP_INT_MAX ? [] : ['fromID' => $from_id])); foreach ($result->entries as $transaction) { // Ensure that $from_id is at its lowest $from_id = min($transaction->refID, $from_id); // Transactions are uniquely identified by applying a // quick hash function over a few identifying fields. // This is because transactionID's may exhaust their // lifetime and lapse. $transaction_hash = $this->hash_transaction($this->corporationID, $account_id, $transaction->date . $transaction->ownerID1, $transaction->ownerID1 . $transaction->refID); // Check if the transaction is known. If it is, // then we can just continue to the next. We will // also use this opportunity to mark that the results // received overlapped an existing record, meaning // that we can stop calling the API for more wallet // transactions. We dont immediately break because // the transactions are not always received in any // order for the fromID that was specified. if (WalletJournalModel::where('corporationID', $this->corporationID)->where('hash', $transaction_hash)->first()) { $transaction_overlap = true; continue; } WalletJournalModel::create(['corporationID' => $this->corporationID, 'hash' => $transaction_hash, 'accountKey' => $account_id, 'refID' => $transaction->refID, 'date' => $transaction->date, 'refTypeID' => $transaction->refTypeID, 'ownerName1' => $transaction->ownerName1, 'ownerID1' => $transaction->ownerID1, 'ownerName2' => $transaction->ownerName2, 'ownerID2' => $transaction->ownerID2, 'argName1' => $transaction->argName1, 'argID1' => $transaction->argID1, 'amount' => $transaction->amount, 'balance' => $transaction->balance, 'reason' => $transaction->reason, 'owner1TypeID' => $transaction->owner1TypeID, 'owner2TypeID' => $transaction->owner2TypeID]); } // Foreach transactions // As previously mentioned, there may be a few // conditions where we may decide its time to // break out of the infinite loop. This is where // we will be doing those checks. The most ob- // vious one being that we may have received less // than the total amount of rows asked for. if (count($result->transactions) < $this->rows_per_call) { break; } // If the response contained known transactions, // stop processing for this character. if ($transaction_overlap) { break; } } // while(true) } // Foreach account_id return; }
/** * Return a Wallet Journal for a Corporation * * @param $corporation_id * @param int $chunk * @param \Illuminate\Http\Request|null $request * * @return mixed * @throws \Seat\Services\Exceptions\FilterException */ public function getCorporationWalletJournal($corporation_id, $chunk = 50, Request $request = null) { $journal = WalletJournal::leftJoin('eve_ref_types', 'corporation_wallet_journals.refTypeID', '=', 'eve_ref_types.refTypeID')->where('corporationID', $corporation_id); // Apply any received filters if ($request && $request->filter) { $journal = $this->where_filter($journal, $request->filter, config('web.filter.rules.corporation_journal')); } return $journal->orderBy('date', 'desc')->paginate($chunk); }