/** * Execute a command and return a response. Does not render * @param IRequest $Request * @return IResponse the execution response */ function execute(IRequest $Request) { $Table = new ProfitTable(); $StatsQuery = $Table->select(ProfitTable::COLUMN_ACCOUNT_ID, 'account')->select(ProfitTable::COLUMN_PROFIT, 'profit', 'SUM(%s)')->select(ProfitTable::COLUMN_PROFIT, 'count', 'COUNT(%s)')->groupBy(ProfitTable::COLUMN_ACCOUNT_ID)->limit(50); $StatsTable = new HTMLPDOQueryTable($StatsQuery); $StatsTable->addColumn('account'); $StatsTable->addColumn('profit'); $StatsTable->addColumn('count'); $StatsTable->addSearchColumn(ProfitTable::COLUMN_ACCOUNT_ID, "account"); $StatsTable->validateRequest($Request); $Form = new HTMLForm(self::FORM_METHOD, $Request->getPath(), self::FORM_NAME, new HTMLMetaTag(HTMLMetaTag::META_TITLE, self::TITLE), new HTMLHeaderStyleSheet(__DIR__ . '/assets/search-profit.css'), new HTMLElement('fieldset', 'fieldset-search fieldset-filter-search inline', new HTMLElement('legend', 'legend-filter-search', self::TITLE), $StatsTable, "<br/>", new HTMLButton(null, 'Report')), "<br/>"); $Form->setFormValues($Request); return $Form; }
/** * Execute a command and return a response. Does not render * @param IRequest $Request * @throws RequestException * @throws \CPath\Request\Validation\Exceptions\ValidationException * @throws \Exception * @return IResponse the execution response */ function execute(IRequest $Request) { $SessionRequest = $Request; if (!$SessionRequest instanceof ISessionRequest) { throw new \Exception("Session required"); } $AccountEntry = AccountEntry::get($this->id); $Account = $AccountEntry->getAccount(); $AffiliateQuery = AccountAffiliationEntry::queryAccountAffiliates($Account->getID()); $AffiliateListTable = new HTMLPDOQueryTable($AffiliateQuery); $AffiliateListTable->addColumn('affiliate'); $AffiliateListTable->addColumn('type'); $Form = new HTMLForm(self::FORM_METHOD, $Request->getPath(), self::FORM_NAME, new HTMLMetaTag(HTMLMetaTag::META_TITLE, self::TITLE), new HTMLHeaderScript(__DIR__ . '/assets/account.js'), new HTMLHeaderStyleSheet(__DIR__ . '/assets/account.css'), new HTMLElement('fieldset', 'fieldset-manage inline', new HTMLElement('legend', 'legend-manage', self::TITLE), new HTMLInputField(self::PARAM_ID, $this->id, 'hidden'), new HTMLInputField(self::PARAM_ACCOUNT_TYPE, $Account->getTypeName(), 'hidden'), new HTMLElement('label', null, "Status<br/>", $SelectStatus = new HTMLSelectField(self::PARAM_ACCOUNT_STATUS, AccountEntry::$StatusOptions, new RequiredValidation())), "<br/><br/>", $Account->getFieldSet($Request), "<br/><br/>", new HTMLButton(self::PARAM_SUBMIT, 'Update', 'update'), new HTMLButton(self::PARAM_SUBMIT, 'Delete', 'delete')), new HTMLElement('fieldset', 'fieldset-affiliates inline', new HTMLElement('legend', 'legend-affiliates', "Add affiliation"), "Account ID:<br/>", new HTMLInputField(self::PARAM_AFFILIATE_ID), "<br/><br/>Affiliation Type:<br/>", $TypeSelect = new HTMLSelectField(self::PARAM_AFFILIATE_TYPE, array("Request New Affiliate" => AccountAffiliationEntry::TYPE_REQUEST_AFFILIATE, "Request New Reseller" => AccountAffiliationEntry::TYPE_REQUEST_RESELLER, "Request New Processor" => AccountAffiliationEntry::TYPE_REQUEST_PROCESSOR)), "<br/><br/>", new HTMLButton(self::PARAM_SUBMIT, 'Request', 'request')), new HTMLElement('fieldset', 'fieldset-affiliate-list inline', new HTMLElement('legend', 'legend-affiliate-list', "Affiliates"), $AffiliateListTable), new HTMLElement('fieldset', 'fieldset-affiliate-approve inline', new HTMLElement('legend', 'legend-affiliate-approve', "Approve Affiliates"), $ApproveSelect = new HTMLSelectField(self::PARAM_APPROVE_AFFILIATE_ID, array('Pending affiliate approvals' => null)), "<br/><br/>", new HTMLButton(self::PARAM_SUBMIT, 'Approve', 'approve'))); $SelectStatus->setInputValue($AccountEntry->getStatus()); $Account = AbstractAccountType::loadFromSession($SessionRequest); if ($Account instanceof AdministratorAccount) { $TypeSelect->setOptions(AccountAffiliationEntry::$TypeOptions); } $AffiliateQuery->addRowCallback(function (AccountAffiliationEntry $Affiliation) use($Account, $ApproveSelect) { if ($Affiliation->getType() & $Affiliation::TYPE_REQUEST_RESELLER && $Affiliation->getAffiliateID() === $Account->getID()) { $ApproveSelect->addOption($Affiliation->getAffiliateID(), "Approve '" . $Affiliation->getTypeText() . "' - " . $Affiliation->getAffiliateID()); } }); if (!$Request instanceof IFormRequest) { return $Form; } $submit = $Request[self::PARAM_SUBMIT]; switch ($submit) { case 'update': $status = $Form->validateField($Request, self::PARAM_ACCOUNT_STATUS); $AccountEntry->update($Request, $Account, $status); return new RedirectResponse(ManageAccount::getRequestURL($this->getAccountID()), "Account updated successfully. Redirecting...", 5); case 'delete': AccountEntry::delete($Request, $this->getAccountID()); return new RedirectResponse(SearchAccounts::getRequestURL(), "Account deleted successfully. Redirecting...", 5); case 'approve': $affiliateID = $Form->validateField($Request, self::PARAM_APPROVE_AFFILIATE_ID); AccountAffiliationEntry::approveAffiliation($Request, $this->getAccountID(), $affiliateID); return new RedirectResponse(SearchAccounts::getRequestURL(), "Account deleted successfully. Redirecting...", 5); case 'request': $affiliateID = $Form->validateField($Request, self::PARAM_AFFILIATE_ID); $type = $Form->validateField($Request, self::PARAM_AFFILIATE_TYPE); AccountAffiliationEntry::setAffiliate($Request, $this->getAccountID(), $affiliateID, $type); return new RedirectResponse(ManageAccount::getRequestURL($this->getAccountID()), "Affiliation requested successfully. Redirecting...", 5); } throw new \InvalidArgumentException($submit); }
/** * Execute a command and return a response. Does not render * @param IRequest $Request * @return IResponse the execution response */ function execute(IRequest $Request) { $SessionRequest = $Request; if (!$SessionRequest instanceof ISessionRequest) { throw new \Exception("Session required"); } $Table = new ProductTable(); $StatsQuery = $Table->select()->limit(50); $StatsTable = new HTMLPDOQueryTable($StatsQuery); $StatsTable->addColumn('product'); $StatsTable->addColumn('type'); $StatsTable->addColumn('total'); $StatsTable->addColumn('account'); $StatsTable->addColumn('description'); $StatsTable->addColumn('fees'); $StatsTable->addColumn('test-url'); $StatsTable->addSearchColumn(ProductTable::COLUMN_ID, "product"); $StatsTable->addSearchColumn(ProductTable::COLUMN_ACCOUNT_ID, "account"); $StatsTable->addSortColumn(ProductTable::COLUMN_ID, "product"); $StatsTable->addSortColumn(ProductTable::COLUMN_ACCOUNT_ID, "account"); $StatsTable->validateRequest($Request); $Account = AbstractAccountType::loadFromSession($SessionRequest); if ($Account instanceof AdministratorAccount) { } else { if ($Account instanceof MerchantAccount) { $StatsQuery->where(ProductTable::COLUMN_ACCOUNT_ID, $Account->getID()); } else { $StatsQuery->where(ProductTable::COLUMN_ACCOUNT_ID, -1); } } $Form = new HTMLForm(self::FORM_METHOD, $Request->getPath(), self::FORM_NAME, new HTMLMetaTag(HTMLMetaTag::META_TITLE, self::TITLE), new HTMLElement('fieldset', new HTMLElement('legend', 'legend-submit', self::TITLE), $StatsTable, new HTMLButton('submit', 'Submit', 'submit')), "<br/>"); return $Form; }
/** * Execute a command and return a response. Does not render * @param IRequest $Request * @throws RequestException * @return IResponse the execution response */ function execute(IRequest $Request) { $SessionRequest = $Request; if (!$SessionRequest instanceof ISessionRequest) { throw new RequestException("Session required"); } $page = 0; $total = null; $row_count = 5; if (isset($Request[self::PARAM_PAGE])) { $page = $Request[self::PARAM_PAGE]; } $offset = $page * $row_count; $Pagination = new HTMLPagination($row_count, $page, $total); $Table = new TransactionTable(); $SearchQuery = $Table->select()->limit("{$row_count} OFFSET {$offset}"); // $SearchQuery->orderBy(TransactionTable::COLUMN_CREATED, "DESC"); $SearchTable = new HTMLPDOQueryTable($SearchQuery); $SearchTable->addColumn('id', "transaction"); $SearchTable->addColumn('product', "product"); $SearchTable->addColumn('wallet', "wallet"); $SearchTable->addColumn('created', "created"); $SearchTable->addColumn('status', "status"); $SearchTable->addColumn('amount', "amount"); $SearchTable->addColumn('email', "email"); $SearchTable->addColumn('product', "product"); $SearchTable->addColumn('currency', "currency"); $SearchTable->addSearchColumn(TransactionTable::COLUMN_ID, "transaction"); $SearchTable->addSearchColumn(TransactionTable::COLUMN_WALLET_ID, "wallet"); $SearchTable->addSearchColumn(TransactionTable::COLUMN_PRODUCT_ID, "product"); $SearchTable->addSortColumn(TransactionTable::COLUMN_CREATED, "created"); $SearchTable->addSortColumn(TransactionTable::COLUMN_STATUS, "status"); $SearchTable->addSortColumn(TransactionTable::COLUMN_AMOUNT, "amount"); $SearchTable->validateRequest($Request); $StatsQuery = $Table->select(TransactionTable::COLUMN_AMOUNT, 'count', 'COUNT(%s)')->select(TransactionTable::COLUMN_AMOUNT, 'total', 'SUM(%s)')->select(TransactionTable::COLUMN_STATUS, 'approves', 'SUM(%s = ' . TransactionEntry::STATUS_APPROVED . ')')->select(TransactionTable::COLUMN_STATUS, 'approves_total', 'SUM(IF(%s = ' . TransactionEntry::STATUS_APPROVED . ', ' . TransactionTable::COLUMN_AMOUNT . ', 0))')->select(TransactionTable::COLUMN_STATUS, 'pending', 'SUM(%s = ' . TransactionEntry::STATUS_PENDING . ')')->select(TransactionTable::COLUMN_STATUS, 'pending_total', 'SUM(IF(%s = ' . TransactionEntry::STATUS_PENDING . ', ' . TransactionTable::COLUMN_AMOUNT . ', 0))')->select(TransactionTable::COLUMN_STATUS, 'declines', 'SUM(%s = ' . TransactionEntry::STATUS_DECLINED . ')')->select(TransactionTable::COLUMN_STATUS, 'declines_total', 'SUM(IF(%s = ' . TransactionEntry::STATUS_DECLINED . ', ' . TransactionTable::COLUMN_AMOUNT . ', 0))')->select(TransactionTable::COLUMN_STATUS, 'refunds', 'SUM(%s = ' . TransactionEntry::STATUS_REFUNDED . ')')->select(TransactionTable::COLUMN_STATUS, 'refunds_total', 'SUM(IF(%s = ' . TransactionEntry::STATUS_REFUNDED . ', ' . TransactionTable::COLUMN_AMOUNT . ', 0))')->select(TransactionTable::COLUMN_STATUS, 'chargebacks', 'SUM(%s = ' . TransactionEntry::STATUS_CHARGE_BACK . ')')->select(TransactionTable::COLUMN_STATUS, 'chargebacks_total', 'SUM(IF(%s = ' . TransactionEntry::STATUS_CHARGE_BACK . ', ' . TransactionTable::COLUMN_AMOUNT . ', 0))')->select(TransactionTable::COLUMN_PAYMENT_SOURCE_ID, PaymentSourceTable::COLUMN_SOURCE, "(Select " . PaymentSourceTable::COLUMN_SOURCE . " FROM " . PaymentSourceTable::TABLE_NAME . " WHERE " . PaymentSourceTable::COLUMN_ID . '=' . TransactionTable::COLUMN_PAYMENT_SOURCE_ID . ")")->select(TransactionTable::COLUMN_PRODUCT_ID, "Product")->groupBy(TransactionTable::COLUMN_PAYMENT_SOURCE_ID . ', ' . TransactionTable::COLUMN_PRODUCT_ID)->limit(50)->addRowCallback(function (&$row) { /** @var AbstractPaymentSource $Source */ $Source = unserialize($row[PaymentSourceTable::COLUMN_SOURCE]); unset($row[PaymentSourceTable::COLUMN_SOURCE]); $cur = $Source->getCurrency(); $row['total '] = vsprintf('(%0d) <span class="total">%1.2f</span>', $row) . ' ' . $cur; unset($row['count'], $row['total']); $row['approves '] = vsprintf('(%0d) <span class="total">%1.2f</span>', $row) . ' ' . $cur; unset($row['approves'], $row['approves_total']); $row['pending '] = vsprintf('(%0d) <span class="total">%1.2f</span>', $row) . ' ' . $cur; unset($row['pending'], $row['pending_total']); $row['declines '] = vsprintf('(%0d) <span class="total">%1.2f</span>', $row) . ' ' . $cur; unset($row['declines'], $row['declines_total']); $row['refunds '] = vsprintf('(%0d) <span class="total">%1.2f</span>', $row) . ' ' . $cur; unset($row['refunds'], $row['refunds_total']); $row['chargebacks '] = vsprintf('(%0d) <span class="total">%1.2f</span>', $row) . ' ' . $cur; unset($row['chargebacks'], $row['chargebacks_total']); }); $StatsTHead = new HTMLPDOQueryTableBody($StatsQuery); $StatsTBody = new HTMLSequenceTableBody($StatsQuery, self::CLS_TABLE_TRANSACTION_SEARCH); $Account = AbstractAccountType::loadFromSession($SessionRequest); if ($Account instanceof MerchantAccount) { $SearchQuery->where(TransactionTable::COLUMN_PRODUCT_ID, $Account->getID(), "IN (Select " . ProductTable::COLUMN_ID . "\n\tFROM " . ProductTable::TABLE_NAME . "\n\tWHERE " . ProductTable::COLUMN_ACCOUNT_ID . " = ?)"); $StatsQuery->where(TransactionTable::COLUMN_PRODUCT_ID, $Account->getID(), "IN (Select " . ProductTable::COLUMN_ID . "\n\tFROM " . ProductTable::TABLE_NAME . "\n\tWHERE " . ProductTable::COLUMN_ACCOUNT_ID . " = ?)"); } else { if ($Account instanceof AdministratorAccount) { // } else if ($Account instanceof ProcessorAccount) { // $SearchQuery->where(TransactionTable::COLUMN_PAYMENT_SOURCE_ID, $Account->getID(), // "IN (Select " . PaymentSourceTable::COLUMN_ID // . "\n\tFROM " . PaymentSourceTable::TABLE_NAME // . "\n\tWHERE " . PaymentSourceTable::C. " = ?)" // ); } else { $SearchQuery->where(TransactionTable::COLUMN_ID, '-1'); } } $Form = new HTMLForm(self::FORM_METHOD, $Request->getPath(), self::FORM_NAME, new HTMLMetaTag(HTMLMetaTag::META_TITLE, self::TITLE), new HTMLHeaderStyleSheet(__DIR__ . '/assets/search-transaction.css'), new HTMLElement('fieldset', 'fieldset-search fieldset-filter-search', new HTMLElement('legend', 'legend-filter-search', self::TITLE), new HTMLElement('fieldset', 'fieldset-filter-stats-results', new HTMLElement('legend', 'legend-filter-stats-results', 'Stats'), new HTMLTable($StatsTHead, $StatsTBody)), "<br/>", new HTMLElement('fieldset', 'fieldset-filter-search-results', new HTMLElement('legend', 'legend-filter-search-results', 'Search Results'), $SearchTable, $Pagination), "<br/>", new HTMLSubmit(null, 'Search')), "<br/>"); $Form->setFormValues($Request); return $Form; }