v7‰PNG
IHDR Ÿ f Õ†C1 sRGB ®Îé gAMA ±üa pHYs à ÃÇo¨d GIDATx^íÜL”÷ð÷Yçªö("Bh_ò«®¸¢§q5kÖ*:þ0AºšÖ¥]VkJ¢M»¶f¸±8\k2íll£1]q®ÙÔ‚ÆT
PK \\>u u db.xmlnu [
PK \, library/CustomUserAccount.phpnu [ _amount = $amount;
}
function getProductId()
{
return $this->account_id;
}
function getType()
{
return 'custom-account';
}
function getTitle()
{
return sprintf('(%s) %s', $this->number, $this->title);
}
function getDescription()
{
return $this->description;
}
function getFirstPrice()
{
return $this->_amount;
}
function getFirstPeriod()
{
return Am_Period::MAX_SQL_DATE;
}
function getRebillTimes()
{
return 0;
}
function getSecondPrice()
{
return null;
}
function getSecondPeriod()
{
return null;
}
function getCurrencyCode()
{
return (string) Am_Currency::getDefault();
}
function getTaxGroup()
{
return 0;
}
function getIsTangible()
{
return false;
}
function getIsCountable()
{
return false;
}
function getQty()
{
return 1;
}
function getIsVariableQty()
{
return false;
}
function getBillingPlanId()
{
return null;
}
function getBillingPlanData()
{
return array();
}
public function getOptions()
{
return $this->_options;
}
public function setOptions(array $options)
{
$this->_options = (array) $options;
}
function calculateStartDate($paymentDate, Invoice $invoice)
{
return $paymentDate;
}
function findItem(array $existingInvoiceItems)
{
return null;
}
function addQty($requestedQty, $itemQty)
{
return 1;
}
}
class CustomUserAccountTable extends Am_Table
{
protected $_key = 'account_id';
protected $_table = '?_custom_user_account';
protected $_recordClass = 'CustomUserAccount';
function getOptions($user_id)
{
return $this->_db->selectCol("SELECT account_id as ARRAY_KEY, CONCAT('(', number, ') ', title)
FROM ?_custom_user_account WHERE user_id=?", $user_id);
}
}PK \a{ { library/Am/Report/Account.phpnu [ title = ___('Transaction Report');
$this->setQuantity(new Am_Report_Quant_Exact(1));
}
public function _initConfigForm(Am_Form $form)
{
parent::_initConfigForm($form);
$form->addSelect('interval', null, array('options' => $this->getDi()->interval->getOptions()))
->setLabel(___('Period'))
->setValue(array(Am_Interval::PERIOD_TODAY));
}
public function runQuery()
{
$vars = $this->form->getValue();
list($start, $stop) = $this->getDi()->interval->getStartStop($vars['interval']);
$point_fld = self::POINT_FLD;
$this->stmt = $this->getDi()->db->queryResultOnly(
"SELECT
dattm,
amount,
CONCAT(u.name_f, ' ', u.name_l) AS name,
CONCAT(t.receipt_id, '/', t.invoice_public_id) AS transaction,
GROUP_CONCAT(item_title SEPARATOR ', ') AS items,
GROUP_CONCAT(DISTINCT cua.number SEPARATOR ', ') AS accounts,
SUBSTR(details, LOCATE('', details) + 16,
LOCATE('', details) - LOCATE('', details) - 16)
AS CardholderName,
invoice_payment_id AS $point_fld
FROM ?_invoice_payment t
LEFT JOIN ?_user u
ON u.user_id=t.user_id
LEFT JOIN ?_invoice_item ii
ON t.invoice_id = ii.invoice_id
LEFT JOIN ?_custom_user_account cua
ON ii.item_type='custom-account' AND ii.item_id = cua.account_id
LEFT JOIN ?_invoice_log il
ON t.invoice_id = il.invoice_id
WHERE dattm BETWEEN ? AND ?
GROUP BY $point_fld", $start, $stop);
}
public function getLines()
{
return array(
new Am_Report_Line('dattm', ___('Transaction Date'), null, 'amDatetime'),
new Am_Report_Line('name', ___('Name on Account')),
new Am_Report_Line('CardholderName', ___('Cardholder Name')),
new Am_Report_Line('accounts', ___('Account Number')),
new Am_Report_Line('transaction', ___('Transaction/Invoice #')),
new Am_Report_Line('amount', ___('Transaction Amount'), null, array('Am_Currency', 'render')),
new Am_Report_Line('items', ___('Invoice Items')),
);
}
public function getOutput(Am_Report_Result $result)
{
return array(
new Am_Report_TableNoTotal($result)
);
}
public function getReport(Am_Report_Result $result = null) {
return parent::getReport(new Am_Report_Result_NoPropagation);
}
}
class Am_Report_Result_NoPropagation extends Am_Report_Result {
protected function populatePoints($start, $values)
{
//nop
}
}
class Am_Report_TableNoTotal extends Am_Report_Output
{
protected $title = "Table";
public function render()
{
$out = "\n";
$out .= "
\n";
$out .= "\n";
foreach ($this->result->getLines() as $line)
$out .= "| " . Am_Controller::escape($line->getLabel()) . " | \n";
$out .= "
\n";
$totals = array();
foreach ($this->result->getPoints() as $point)
{
if (!$point->hasValues()) continue;
$out .= "";
$i = 0;
foreach ($this->result->getLines() as $line)
{
$out .= sprintf("| %s | ", Am_Controller::escape($line->formatValue($point->getValue($line->getKey()))));
@$lines[$i] = $line;
}
$out .= "
\n";
}
$out .= "
\n";
$out .= "
";
return $out;
}
}PK \P* library/SetupForms.phpnu [ setTitle(___('Accounts'));
}
function initElements()
{
$this->addMagicSelect('custom-account.paysys_id')
->loadOptions($this->getOptions())
->setLabel(___("Available Payment Systems\n" .
"keep empty to use all public"));
}
function getOptions()
{
$options = array();
foreach (Am_Di::getInstance()->paysystemList->getAllPublic() as $ps) {
$options[$ps->getId()] = $ps->getId();
}
return $options;
}
}PK \O; ; email-templates.xmlnu [
custom-account.balance_updated
en
text
Account Updated [%account.number%]
Dear %user.name_f% %user.name_l%,
Your account %account.number% (%account.title%)
has been updated by administrator.
New balance of your account is %account.balance|currency%
--
Best Regards,
%site_title%
%root_url%
PK \+>
Bootstrap.phpnu [ addReturn(___('Account: Can manage user Accounts'), self::ADMIN_PERM_ID);
}
function onInitFinished(Am_Event $e)
{
$this->getDi()->invoiceItemTable->registerItemLoader('custom-account', 'customUserAccountTable');
$router = Zend_Controller_Front::getInstance()->getRouter();
$router->addRoute('custom-account-pay', new Zend_Controller_Router_Route(
'bill/pay', array(
'module' => 'custom-account',
'controller' => 'pay',
'action' => 'index'
)
));
$this->getDi()->blocks->add(new Am_Block('member/main/left', ___('Accounts'), 'accounts', $this, array($this, 'renderBlock')));
}
function onLoadReports()
{
require_once 'Am/Report/Account.php';
}
function onUserMerge(Am_Event $event)
{
$target = $event->getTarget();
$source = $event->getSource();
$this->getDi()->db->query('UPDATE ?_custom_user_account SET user_id=? WHERE user_id=?',
$target->pk(), $source->pk());
}
function onUserAfterDelete(Am_Event_UserAfterDelete $event)
{
$this->getDi()->db->query("DELETE FROM ?_custom_user_account WHERE user_id=?", $event->getUser()->user_id);
}
function renderBlock(Am_View $v)
{
$user = $this->getDi()->user;
$accounts = $this->getDi()->customUserAccountTable->findByUserId($user->pk());
if (!$accounts)
return 'You have not accounts yet';
$out = '';
foreach ($accounts as $a) {
$out .= sprintf('%s (%s) - %s
%s', $a->number, $a->title, Am_Currency::render($a->balance), $a->description);
}
return sprintf('', $out);
}
function onAdminMenu(Am_Event $e)
{
$page = $e->getMenu()->findOneBy('id', 'users');
$page->addPage(array(
'label' => ___('Update Accounts'),
'controller' => 'admin-account',
'action' => 'index',
'module' => 'custom-account',
'id' => 'custom-account',
'resource' => self::ADMIN_PERM_ID
));
$page->addPage(array(
'label' => ___('Upload Account Files'),
'controller' => 'admin-account',
'action' => 'upload',
'module' => 'custom-account',
'id' => 'custom-account-upload',
'resource' => self::ADMIN_PERM_ID
));
}
function onUserTabs(Am_Event_UserTabs $e)
{
$e->getTabs()->addPage(array(
'id' => 'account',
'module' => 'custom-account',
'controller' => 'admin-user',
'action' => 'index',
'params' => array(
'user_id' => $e->getUserId()
),
'label' => ___('Accounts'),
'order' => 1000,
'resource' => self::ADMIN_PERM_ID,
));
}
function onUserMenu(Am_Event $e)
{
$user = $e->getUser();
if ($this->getDi()->db->selectCell("SELECT COUNT(*) FROM ?_custom_user_account
WHERE user_id=?", $user->pk())) {
$e->getMenu()->addPage(array(
'id' => 'account',
'label' => ___('Pay Your Bill'),
'controller' => 'pay',
'action' => 'index',
'module' => 'custom-account',
'route' => 'custom-account-pay',
'order' => 3,
));
}
}
function onSetupEmailTemplateTypes(Am_Event $event)
{
$event->addReturn(array(
'id' => 'custom-account.balance_updated',
'title' => 'Account Updated',
'mailPeriodic' => Am_Mail::REGULAR,
'vars' => array('user',
'account.number' => 'Account Number',
'account.title' => 'Account Title',
'account.balance' => 'Account Balance',
),
), 'custom-account.balance_updated');
}
}PK \M
module.xmlnu [
custom-account
Account
Handle Payments to User Accounts
@@VERSION@@
PK \-W W controllers/PayController.phpnu [ getDi()->auth->requireLogin(REL_ROOT_URL . '/custom-balance/pay');
}
function indexAction()
{
$form = $this->createForm();
$errors = array();
if ($form->isSubmitted() && $form->validate()) {
$vars = $form->getValue();
$invoice = $this->getDi()->invoiceRecord;
foreach ($vars['account_id'] as $id) {
$account = $this->getDi()->customUserAccountTable->load($id);
if ($account->user_id != $this->getDi()->user->user_id)
throw new Am_Exception_AccessDenied;
if (!$vars['amount'][$id]) {
$errors[] = ___('Please specify amount for account %s', $account->number);
}
$account->setAmount($vars['amount'][$id]);
$invoice->add($account);
}
if (!$invoice->getItems()) {
$errors[] = ___('You need to choose at least one account to pay for');
}
if ($errors) {
$form->setError(implode(', ', $errors));
goto form;
}
$invoice->calculate();
$invoice->setPaysystem($vars['paysys_id']);
$invoice->setUser($this->getDi()->user);
$err = $invoice->validate();
if ($err)
throw new Am_Exception_InputError($err[0]);
$invoice->save();
$payProcess = new Am_Paysystem_PayProcessMediator($this, $invoice);
$result = $payProcess->process();
throw new Am_Exception_InternalError(
sprintf('Error occurred while trying proccess invoice [%s]', filterId($invoice->public_id)));
}
form:
$this->view->title = ___('Pay Your Bill');
$this->view->content = (string) $form;
$this->view->display('member/layout.phtml');
}
function createForm()
{
$aOptions = array();
$dAmount = array();
foreach ($this->getDi()->customUserAccountTable->findByUserId($this->getDi()->auth->getUserId()) as $a) {
$aOptions[$a->pk()] = $this->renderAccount($a);
$dAmount[$a->pk()] = $a->balance;
}
$form = new Am_Form('pay');
$account = $form->addGroup()
->setLabel(___('Account'));
$account->setSeparator('
');
foreach ($aOptions as $k => $v) {
$gr = $account->addGroup();
if (count($aOptions) == 1) {
$gr->addHidden("account_id[$k]", array('value' => $k));
$gr->addStatic()
->setContent($v);
}
else {
$gr->addCheckbox("account_id[$k]", array('value' => $k, 'class' => 'account'), array('content' => $v));
}
$gr->addText("amount[$k]", array('size' => 10, 'style' => 'clear:both; display:block', 'placeholder' => ___('Amount to Pay')))
->setId('amount-' . $k);
}
$form->addScript()
->setScript(<<getPsOptions();
if (count($psOptions) > 1) {
$paysys = $form->addAdvRadio('paysys_id')
->setLabel(___('Payment System'))
->loadOptions($psOptions);
$paysys->addRule('required', ___('Please choose a payment system'));
}
else {
$form->addHidden('paysys_id')
->setValue(key($psOptions));
}
$form->addSaveButton('Pay');
$form->addDataSource(new HTML_QuickForm2_DataSource_Array(array('amount' => $dAmount)));
return $form;
}
protected function renderAccount($a)
{
return sprintf('%s (%s) - %s
%s', $a->number, $a->title, Am_Currency::render($a->balance), $a->description);
}
protected function getPsOptions()
{
$paysystems = array();
if (!$this->getModule()->getConfig('paysys_id', array())) {
$paysystems = $this->getDi()->paysystemList->getAllPublic();
}
else {
foreach ($this->getModule()->getConfig('paysys_id') as $ps_id) {
try {
$ps = $this->getDi()->paysystemList->get($ps_id);
}
catch (Exception $e) {
$this->getDi()->errorLogTable->logException($e);
continue;
}
$paysystems[] = $ps;
}
}
$options = array();
foreach ($paysystems as $ps) {
$options[$ps->getId()] = $this->renderPaysys($ps);
}
return $options;
}
protected function renderPaysys(Am_Paysystem_Description $p)
{
return sprintf('%s %s', $p->getTitle(), $p->getDescription());
}
}PK \άz> &