/** * @return Am_Currency */ function getCurrency($value = null) { $c = new Am_Currency($this->currency); if ($value) { $c->setValue($value); } return $c; }
function init() { $this->addDataSource(new HTML_QuickForm2_DataSource_Array(array('_count' => 1, 'use_count' => 10, 'discount' => 10, 'discount_type' => '%', 'user_use_count' => 1, '_code_len' => 8))); if (!$this->record->isLoaded()) { $this->addElement('text', '_count', array('size' => 20))->setLabel(___("Coupons Count\nhow many coupons need to be generated"))->addRule('gt', 'Should be greater than 0', 0); } $this->addElement('text', 'use_count', array('size' => 20))->setLabel(___("Coupons Usage Count\n" . "how many times coupon can be used")); $discountGroup = $this->addElement('group')->setLabel(array('Discount')); $discountGroup->addElement('text', 'discount', array('size' => 5))->addRule('gt', 'must be greater than 0', 0); $discountGroup->addElement('select', 'discount_type')->loadOptions(array(Coupon::DISCOUNT_PERCENT => '%', Coupon::DISCOUNT_NUMBER => Am_Currency::getDefault())); $this->addElement('textarea', 'comment')->setLabel(___("Comment\nfor admin reference")); /// advanced settings $fs = $this->addAdvFieldset('advanced')->setLabel(___('Advanced Settings')); if (!$this->record->isLoaded()) { $fs->addElement('text', '_code_len', array('size' => 20))->setLabel(array(___("Code Length\ngenerated coupon code length\nbetween 5 and 32")))->addRule('gt', 'Should be greater than 4', 4)->addRule('lt', 'Should be less then 33', 33); } $fs->addElement('text', 'user_use_count', array('size' => 20))->setLabel(___("User Coupon Usage Count\nhow many times a coupon code can be used by customer")); $dateGroup = $fs->addElement('group')->setLabel(___("Dates\ndate range when coupon can be used")); $dateGroup->addCheckbox('_date-enable', array('class' => 'enable_date')); $begin = $dateGroup->addDate('begin_date'); $expire = $dateGroup->addDate('expire_date'); $fs->addElement('advcheckbox', 'is_recurring')->setLabel(___("Apply to recurring?\n" . "apply coupon discount to recurring rebills?")); $fs->addElement('advcheckbox', 'is_disabled')->setLabel(___("Is Disabled?\n" . "If you disable this coupons batch, it will\n" . "not be available for new purchases.\n" . "Existing invoices are not affected.\n")); $fs->addElement('select', 'product_ids', array('multiple' => 1, 'class' => 'magicselect'))->loadOptions(Am_Di::getInstance()->productTable->getOptions())->setLabel(___("Products\n" . "coupons can be used with selected products only.\n" . "if nothing selected, coupon can be used with any product")); $jsCode = <<<CUT \$(".enable_date").prop("checked", \$("input[name=expire_date]").val() ? "checked" : ""); \$(".enable_date").live("change", function(){ var dates = \$(this).parent().find("input[type=text]"); dates.prop('disabled', \$(this).prop("checked") ? '' : 'disabled'); }).trigger("change"); CUT; $fs->addScript('script')->setScript($jsCode); }
public function __construct($name = null, $attributes = null, $data = null) { parent::__construct($name, $attributes, null); $this->addElement('text', $data . '_c', array('size' => 5)); $this->addStatic()->setContent(' '); $sel = $this->addElement('select', $data . '_t', array('size' => 1), array('options' => array('%' => '%', '$' => Am_Currency::getDefault()))); }
public function createForm() { $form = new Am_Form_Admin(); $options = Am_Currency::getSupportedCurrencies(); array_remove_value($options, Am_Currency::getDefault()); $sel = $form->addSelect('currency', array('class' => 'am-combobox'))->setLabel(___('Currency'))->loadOptions($options)->addRule('required'); $date = $form->addDate('date')->setLabel(___('Date'))->addRule('required')->addRule('callback2', "--wrong date--", array($this, 'checkDate')); $rate = $form->addText('rate', array('length' => 8))->setLabel(___("Exchange Rate\nenter cost of 1 (one) %s", Am_Currency::getDefault()))->addRule('required'); return $form; }
public function insert($reload = true) { if ($this->currency == Am_Currency::getDefault()) { $this->base_currency_multi = 1.0; } else { $this->base_currency_multi = $this->getDi()->currencyExchangeTable->getRate($this->currency, sqlDate($this->dattm)); } $ret = parent::insert($reload); $this->getDi()->hook->call('refundAfterInsert', array('invoice' => $this->getInvoice(), 'refund' => $this, 'user' => $this->getInvoice()->getUser())); return $ret; }
function init() { $this->addElement('hidden', 'product_id'); $this->addRule('callback', ___('At least one billing plan must be added'), array($this, 'checkBillingPlanExists')); /* General Settings */ $fieldSet = $this->addElement('fieldset', 'general')->setLabel(___('General Settings')); $fieldSet->addElement('text', 'title', array('size' => 40, 'class' => 'translate'))->setLabel(___('Title'))->addRule('required'); $fieldSet->addElement('textarea', 'description', array('class' => 'translate'))->setLabel(___("Description\n" . "displayed to visitors on order page below the title"))->setAttribute('cols', 40)->setAttribute('rows', 2); $fieldSet->addElement('textarea', 'comment')->setLabel(___("Comment\nfor admin reference"))->setAttribute('cols', 40)->setAttribute('rows', 2); $gr = $fieldSet->addGroup()->setSeparator(' ')->setLabel(___('Product Categories')); $gr->addMagicSelect('_categories')->loadOptions(Am_Di::getInstance()->productCategoryTable->getAdminSelectOptions()); $gr->addStatic()->setContent('<a href="' . Am_Controller::escape(REL_ROOT_URL) . '/admin-product-categories">' . ___('Edit Groups') . '</a>'); /* Billing Settings */ $fieldSet = $this->addElement('fieldset', 'billing')->setLabel(___('Billing')); if (Am_Di::getInstance()->config->get('use_tax')) { $fieldSet->addElement('advcheckbox', 'no_tax')->setLabel(___('Do not Apply Tax?')); } $fieldSet->addElement('select', 'currency')->setLabel(array(___("Currency"), ___("you can choose from list of currencies supported by paysystems")))->loadOptions(Am_Currency::getSupportedCurrencies('ru_RU')); // if (Am_Di::getInstance()->config->get('product_paysystem')) { // $fieldSet->addElement('select', 'paysys_id') // ->setLabel(array('Payment System', // "choose a payment system to be used exclusively with this product")) // ->loadOptions(array('' => '* Choose a paysystem *') + Am_Di::getInstance()->paysystemList->getOptions()); // }; // $this->addBillingPlans(); /* Advanced Settings */ // $fieldSet = $this->addElement('fieldset', 'advanced') // ->setId('advanced') // ->setLabel(___('Advanced')); // $fieldSet->addElement('text', 'trial_group', array('size' => 20)) // ->setLabel(___("Trial Group\n". // 'If this field is filled-in, user will be unable to order the product // twice. It is extermelly useful for any trial product. This field // can have different values for different products, then "trial history" // will be separate for these groups of products. // If your site offers only one level of membership, // just enter "1" to this field. ')); /* Product availability */ $fieldSet = $this->addElement('fieldset', 'avail')->setLabel(___('Product Availability')); $this->insertAvailablilityFields($fieldSet); $sdGroup = $fieldSet->addGroup()->setLabel(___("Start Date Calculation\n" . "rules for subscription start date calculation.\n" . "MAX date from alternatives will be chosen.\n" . "This settings has no effect for recurring subscriptions")); $sd = $sdGroup->addSelect('start_date', array('multiple' => 'mutliple', 'id' => 'start-date-edit')); $sd->loadOptions(array(Product::SD_PRODUCT => ___('Last existing subscription date of this product'), Product::SD_GROUP => ___('Last expiration date in the renewal group: '), Product::SD_FIXED => ___('Fixed date'), Product::SD_PAYMENT => ___('Payment date'))); $sdGroup->addSelect('renewal_group', array('style' => 'display:none; font-size: xx-small'), array('intrinsic_validation' => false, 'options' => Am_Di::getInstance()->productTable->getRenewalGroups())); $sdGroup->addDate('start_date_fixed', array('style' => 'display:none; font-size: xx-small')); $fieldSet->addElement('text', 'sort_order')->setLabel(___("Sorting order\n" . "This is a numeric field. Products are sorted\n" . "according to this field value, then alphabetically")); /* Additional Options */ $fieldSet = $this->addElement('fieldset', 'additional')->setId('additional')->setLabel(___('Additional')); $this->insertAdditionalFields(); Am_Di::getInstance()->hook->call(Am_Event::PRODUCT_FORM, array('form' => $this)); }
function initElements() { $this->addElement('text', 'site_title', array('size' => 40), array('help-id' => '#Site Title'))->setLabel(___('Site Title')); $this->addElement('static', null, null, array('help-id' => '#Root Url and License Key'))->setContent('<div><a href="' . Am_Controller::escape(REL_ROOT_URL) . '/admin-license" target="_top">' . ___('change') . '</a></div>')->setLabel(___('Root Url and License Keys')); $this->addText('flowplayer_license')->setLabel(___("FlowPlayer License Key\nyou may get your key in %smembers area%s", '<a href="http://www.amember.com/amember/member?flowplayer_key=1">', '</a>'))->addRule('regex', ___('Value must be alphanumeric'), '/^[a-zA-Z0-9]*$/'); $this->addElement('select', 'theme', null, array('help-id' => '#User Pages Theme'))->setLabel(___('User Pages Theme'))->loadOptions(Am_View::getThemes('user')); $this->addElement('select', 'admin_theme')->setLabel(___('Admin Pages Theme'))->loadOptions(Am_View::getThemes('admin')); /* if (!extension_loaded("curl")){ $el = $this->addElement('text', 'curl') ->setLabel(___('cURL executable file location', "you need it only if you are using payment processors<br /> like Authorize.Net or PayFlow Pro<br /> usually valid path is /usr/bin/curl or /usr/local/bin/curl")); $el->default = '/usr/bin/curl'; $el->addRule('callback2', 'error', array($this, 'validateCurl')); } */ $fs = $this->addElement('fieldset', '##02')->setLabel(___('Signup Form Configuration')); // $this->addElement('advcheckbox', 'generate_login') // ->setLabel(___('Generate Login', 'should aMember generate username for customer?')); $this->setDefault('login_min_length', 5); $this->setDefault('login_max_length', 16); $loginLen = $fs->addGroup()->setLabel(___('Username length')); $loginLen->addInteger('login_min_length')->setLabel('min'); $loginLen->addInteger('login_max_length')->setLabel('max'); $fs->addElement('advcheckbox', 'login_disallow_spaces')->setLabel(___('Do not allow spaces in username')); $fs->addElement('advcheckbox', 'login_dont_lowercase')->setLabel(___("Do not lowercase username\n" . "by default, aMember automatically lowercases entered username\n" . "here you can disable this function")); // $fs->addElement('advcheckbox', 'generate_pass') // ->setLabel(___('Generate Password', 'should aMember generate password for customer?')); // $this->setDefault('pass_min_length', 6); $this->setDefault('pass_max_length', 25); $passLen = $fs->addGroup()->setLabel(___('Password Length')); $passLen->addInteger('pass_min_length')->setLabel('min'); $passLen->addInteger('pass_max_length')->setLabel('max'); $fs = $this->addElement('fieldset', '##03')->setLabel(___('Miscellaneous')); $this->setDefault('admin.records-on-page', 10); $fs->addElement('text', 'admin.records-on-page')->setLabel(___('Records per page (for grids)')); $this->setDefault('currency', 'USD'); $currency = $fs->addElement('select', 'currency', array('size' => 1))->setLabel(___("Base Currency\n" . "base currency to be used for reports and affiliate commission.\n" . "It could not be changed if there are any invoices in database"))->loadOptions(Am_Currency::getFullList()); if (Am_Di::getInstance()->db->selectCell("SELECT COUNT(*) FROM ?_invoice")) { $currency->toggleFrozen(true); } }
public function renderOut(&$out) { $titles = array(); $this->ds->clearFields()->clearOrder()->toggleAutoGroupBy(false); foreach ($this->fields as $field) { /* @var $field Am_Grid_Field */ $name = $field->getFieldName(); $stm = $this->stms[$name]; $this->ds->addField(sprintf("SUM({$stm})", $name), '_' . $name); $titles['_' . $name] = $field->getFieldTitle(); } $totals = array(); foreach (Am_Di::getInstance()->db->selectRow($this->ds->getSql()) as $key => $val) { $totals[] = sprintf('%s %s: <strong>%s</strong>', ___('Total'), $titles[$key], Am_Currency::render($val)); } $count = count($this->grid->getFields()); $tr = sprintf('<tr><td class="grid-total" colspan="%d">%s</td></td>', $count, implode(',', $totals)); $out = preg_replace('|(<tr>\\s*<th>)|', str_replace('$', '\\$', $tr) . '\\1', $out); }
function init() { $this->addElement('hidden', 'product_id'); $this->addRule('callback', ___('At least one billing plan must be added'), array($this, 'checkBillingPlanExists')); /* General Settings */ $fieldSet = $this->addElement('fieldset', 'general')->setLabel(___('General Settings')); $fieldSet->addElement('text', 'title', array('size' => 40, 'class' => 'translate'))->setLabel(___('Title'))->addRule('required'); $fieldSet->addElement('textarea', 'description', array('class' => 'translate'))->setLabel(___("Description\n" . "displayed to visitors on order page below the title"))->setAttribute('cols', 40)->setAttribute('rows', 2); $fieldSet->addElement('textarea', 'comment', array('class' => 'el-wide'))->setLabel(___("Comment\nfor admin reference"))->setAttribute('rows', 2); $fieldSet->addCategory('_categories', null, array('base_url' => 'admin-product-categories', 'link_title' => ___('Edit Categories'), 'title' => ___('Product Categories'), 'options' => Am_Di::getInstance()->productCategoryTable->getOptions()))->setLabel(___('Product Categories')); /* Billing Settings */ $fieldSet = $this->addElement('fieldset', 'billing', array('id' => 'billing'))->setLabel(___('Billing')); $fieldSet->addElement('advcheckbox', 'tax_group', array('value' => IProduct::ALL_TAX))->setLabel(___('Apply Tax?')); $fieldSet->addElement('select', 'currency', array('class' => 'am-combobox'))->setLabel(___("Currency\n" . 'you can choose from list of currencies supported by paysystems'))->loadOptions(Am_Currency::getSupportedCurrencies('ru_RU')); $this->addBillingPlans(); // $fieldSet->addElement('text', 'trial_group', array('size' => 20)) // ->setLabel(___("Trial Group\n". // 'If this field is filled-in, user will be unable to order the product // twice. It is extermelly useful for any trial product. This field // can have different values for different products, then "trial history" // will be separate for these groups of products. // If your site offers only one level of membership, // just enter "1" to this field. ')); /* Product availability */ $fieldSet = $this->addAdvFieldset('avail')->setLabel(___('Product Availability')); $this->insertAvailablilityFields($fieldSet); $sdGroup = $fieldSet->addGroup()->setLabel(___("Start Date Calculation\n" . "rules for subscription start date calculation.\n" . "MAX date from alternatives will be chosen.\n" . "This settings has no effect for recurring subscriptions")); $sd = $sdGroup->addSelect('start_date', array('multiple' => 'mutliple', 'id' => 'start-date-edit')); $sd->loadOptions(array(Product::SD_PRODUCT => ___('Last existing subscription date of this product'), Product::SD_GROUP => ___('Last expiration date in the renewal group'), Product::SD_FIXED => ___('Fixed date'), Product::SD_PAYMENT => ___('Payment date'), ___('Nearest') => array(Product::SD_WEEKDAY_SUN => ___('Nearest Sunday'), Product::SD_WEEKDAY_MON => ___('Nearest Monday'), Product::SD_WEEKDAY_TUE => ___('Nearest Tuesday'), Product::SD_WEEKDAY_WED => ___('Nearest Wednesday'), Product::SD_WEEKDAY_THU => ___('Nearest Thursday'), Product::SD_WEEKDAY_FRI => ___('Nearest Friday'), Product::SD_WEEKDAY_SAT => ___('Nearest Saturday'), Product::SD_MONTH_1 => ___('Nearest 1st Day of Month'), Product::SD_MONTH_15 => ___('Nearest 15th Day of Month')))); $sdGroup->addDate('start_date_fixed', array('style' => 'display:none; font-size: xx-small')); $rgroups = Am_Di::getInstance()->productTable->getRenewalGroups(); $roptions = array('' => ___('-- Please Select --')); if ($rgroups) { $roptions = array_merge($roptions, array_filter($rgroups)); } $fieldSet->addSelect('renewal_group', array(), array('intrinsic_validation' => false, 'options' => $roptions))->setLabel(___("Renewal Group\n" . "Allows you to set up sequential or parallel subscription periods. " . "Subscriptions from the same group will begin at the end of " . "subscriptions from the same group. Subscriptions from different " . "groups can run side-by-side")); /* Additional Options */ $this->insertAdditionalFields(); $this->addAdvCheckbox('is_archived')->setLabel(___("Is Archived?\n" . "archived product will be removed from all lists")); }
public function validateTerms() { return $this->request->getParam('Ds_Amount') / 100 == $this->invoice->first_total && $this->request->getParam('Ds_Currency') == Am_Currency::getNumericCode($this->invoice->currency); }
function getLines() { return array(new Am_Report_Line("amt", "Payments Amount, " . Am_Currency::getDefault(), "#ff00cc")); }
/** * @return array of 3-letter ISO currency codes supported by this payment system like array('USD', 'EUR'); */ function getSupportedCurrencies() { return array(Am_Currency::getDefault()); }
function renderConditions() { $ret = array(); foreach ($this->getConditions() as $conditionType => $vars) { switch ($conditionType) { case self::COND_AFF_SALES_COUNT: $ret[] = sprintf("affiliate generated %d sales last %d days", $vars['count'], $vars['days']); case self::COND_AFF_SALES_AMOUNT: $ret[] = sprintf("affiliate generated %d%s in commissions last %d days", $vars['count'], Am_Currency::getDefault(), $vars['days']); break; case self::COND_AFF_GROUP_ID: $v = array(); foreach ($this->getDi()->userGroupTable->loadIds((array) $vars) as $group) { $v[] = $group->title; } $ret[] = sprintf("affiliate group IN (%s)", implode(", ", $v)); break; case self::COND_PRODUCT_ID: $v = array(); foreach ($this->getDi()->productTable->loadIds((array) $vars) as $product) { $v[] = $product->title; } $ret[] = sprintf("products IN (%s)", implode(", ", $v)); break; case self::COND_PRODUCT_CATEGORY_ID: $v = array(); foreach ($this->getDi()->productCategoryTable->loadIds((array) $vars) as $product) { $v[] = $product->title; } $ret[] = sprintf("product category IN (%s)", implode(", ", $v)); break; default: return false; } } return implode(" AND ", $ret); }
function renderPayments(User $record) { if ($record->payments_count) { $curr = new Am_Currency(); $curr->setValue($record->payments_sum); $text = $record->payments_count . ' - ' . $curr->toString(); $link = REL_ROOT_URL . "/admin-user-payments/index/user_id/{$record->user_id}"; $text = sprintf('<a class="link" target="_top" href="%s#payments">%s</a>', $link, $text); } else { $text = ___('Never'); } return sprintf('<td>%s</td>', $text); }
function render($indent = "", InvoicePayment $payment = null) { $prefix = !is_null($payment) && !$payment->isFirst() ? 'second' : 'first'; $tm_added = is_null($payment) ? $this->tm_added : $payment->dattm; $newline = "\r\n"; $price_width = max(mb_strlen(Am_Currency::render($this->{$prefix . '_total'}, $this->currency)), 8); $column_padding = 1; $column_title_max = 60; $column_title_min = 20; $column_qty = 4 + $price_width; $column_num = 3; $column_amount = $price_width; $space = str_repeat(' ', $column_padding); $max_length = 0; foreach ($this->getItems() as $item) { $max_length = max(mb_strlen(___($item->item_title)), $max_length); } $column_title = max(min($max_length, $column_title_max), $column_title_min); $row_width = $column_num + $column_padding + $column_title + $column_padding + $column_qty + $column_padding + $column_amount + $column_padding; $column_total = $column_title + $column_qty + $column_padding; $total_space = str_repeat(' ', $column_padding + $column_num + $column_padding); $border = $indent . str_repeat('-', $row_width) . "{$newline}"; $out = $indent . ___("Invoice") . ' #' . $this->public_id . " / " . amDate($tm_added) . "{$newline}"; $out .= $border; $num = 1; foreach ($this->getItems() as $item) { $title = explode("\n", $this->wordWrap(___($item->item_title), $column_title, "\n", true)); $out .= $indent . sprintf("{$space}%{$column_num}s{$space}%-{$column_title}s{$space}%{$column_qty}s{$space}%{$price_width}s{$newline}", $num . '.', $title[0], $item->qty . 'x' . Am_Currency::render($item->{$prefix . '_price'}, $this->currency), Am_Currency::render($item->{$prefix . '_total'}, $this->currency)); for ($i = 1; $i < count($title); $i++) { $out .= $indent . sprintf("{$space}%{$column_num}s{$space}%-{$column_title}s{$newline}", ' ', $title[$i]); } $num++; } $out .= $border; if ($this->{$prefix . '_subtotal'} != $this->{$prefix . '_total'}) { $out .= $indent . sprintf("{$total_space}%-{$column_total}s{$space}%{$price_width}s{$newline}", ___('Subtotal'), Am_Currency::render($this->{$prefix . '_subtotal'}, $this->currency)); } if ($this->{$prefix . '_discount'} > 0) { $out .= $indent . sprintf("{$total_space}%-{$column_total}s{$space}%{$price_width}s{$newline}", ___('Discount'), Am_Currency::render($this->{$prefix . '_discount'}, $this->currency)); } if ($this->{$prefix . '_shipping'} > 0) { $out .= $indent . sprintf("{$total_space}%-{$column_total}s{$space}%{$price_width}s{$newline}", ___('Shipping'), Am_Currency::render($this->{$prefix . '_shipping'}, $this->currency)); } if ($this->{$prefix . '_tax'} > 0) { $out .= $indent . sprintf("{$total_space}%-{$column_total}s{$space}%{$price_width}s{$newline}", ___('Tax') . sprintf(' (%d%s)', $this->tax_rate, '%'), Am_Currency::render($this->{$prefix . '_tax'}, $this->currency)); } $out .= $indent . sprintf("{$total_space}%-{$column_total}s{$space}%{$price_width}s{$newline}", ___('Total'), Am_Currency::render($this->{$prefix . '_total'}, $this->currency)); $out .= $border; if ($this->rebill_times) { $terms = explode("\n", $this->wordWrap(___($this->getTerms()), $row_width, "\n", true)); foreach ($terms as $term_part) { $out .= $indent . $term_part . $newline; } $out .= $border; } return $out; }
public function keywordsAction() { $uid = $this->getDi()->auth->getUserId(); $db = $this->getDi()->db; $db->query('DROP TEMPORARY TABLE IF EXISTS ?_aff_keywords_tmp'); $db->query("CREATE TEMPORARY TABLE ?_aff_keywords_tmp (\n keyword_id int not null DEFAULT 0,\n keyword varchar(64) not null DEFAULT '',\n clicks_count int not null DEFAULT 0,\n leads_count int not null DEFAULT 0,\n sales_count int not null DEFAULT 0,\n sales_amount int not null DEFAULT 0,\n PRIMARY KEY (`keyword_id`)\n )"); //clicks $db->query("INSERT into ?_aff_keywords_tmp (keyword_id, clicks_count) \n SELECT keyword_id, count(*) from ?_aff_click where keyword_id is not null and aff_id = ? group by keyword_id", $uid); //leads $db->query("INSERT into ?_aff_keywords_tmp (keyword_id, leads_count) \n SELECT keyword_id, cnt from (SELECT keyword_id, count(*) as cnt from ?_aff_lead \n where keyword_id is not null and aff_id = ? group by keyword_id) s\n ON DUPLICATE KEY UPDATE leads_count = s.cnt", $uid); //sales_count $db->query("INSERT into ?_aff_keywords_tmp (keyword_id, sales_count) \n SELECT keyword_id, cnt from (SELECT keyword_id, sum(if(record_type='commission', 1, 0)) as cnt from ?_aff_commission \n where keyword_id is not null and aff_id = ? group by keyword_id) s\n ON DUPLICATE KEY UPDATE sales_count = s.cnt", $uid); //sales_amount $db->query("INSERT into ?_aff_keywords_tmp (keyword_id, sales_amount) \n SELECT keyword_id, cnt from (SELECT keyword_id, sum(if(record_type='commission', amount, -amount)) as cnt from ?_aff_commission \n where keyword_id is not null and aff_id = ? group by keyword_id) s\n ON DUPLICATE KEY UPDATE sales_amount = s.cnt", $uid); //keyword $db->query("UPDATE ?_aff_keywords_tmp t set keyword = (SELECT value from ?_aff_keyword s where s.keyword_id = t.keyword_id)"); $ds = new Am_Query(new Am_Table($db, '?_aff_keywords_tmp', 't')); $grid = new Am_Grid_ReadOnly('_aff_keywords', 'Keywords', $ds, $this->getRequest(), $this->getView()); $grid->addField('keyword', ___('Keyword')); $grid->addField('clicks_count', ___('Clicks')); $grid->addField('leads_count', ___('Leads')); $grid->addField('sales_count', ___('Sales')); $grid->addField('sales_amount', ___('Commissions'))->setRenderFunction(function ($record) { return "<td>" . Am_Currency::render($record->sales_amount) . "</td>"; }); $grid->runWithLayout('aff/keywords.phtml'); }
public function getUsedCount($obj) { $invoices = Am_Di::getInstance()->invoiceTable->findByCouponId($obj->coupon_id); if (!$invoices) { return ''; } $ret = array(); $out = ''; $wrap = '<strong>' . ___('Transactions with this coupon:') . '</strong>' . '<div><table class="grid">' . '<tr><th>' . ___('User') . '</th><th>' . ___('Invoice') . '</th><th>' . ___('Date/Time') . '</th><th>' . ___('Receipt#') . '</th><th>' . ___('Amount') . '</th><th>' . ___('Discount') . '</th></tr>' . '%s</table></div>'; $tpl = '<tr><td>%s (%s %s)</td><td>%d/%s</td><td>%s</td><td>%s</td><td>%s</td><td><strong>%s</strong></td></tr>'; foreach ($invoices as $invoice) { if ($invoice->getStatus() == Invoice::PENDING) { continue; } $payments = $this->getDi()->invoicePaymentTable->findBy(array('invoice_id' => $invoice->invoice_id, 'discount' => '<>0'), null, null, "invoice_payment_id"); foreach ($payments as $payment) { $user = Am_Di::getInstance()->userTable->load($payment->user_id); $ret[] = sprintf($tpl, $this->getDi()->view->escape($user->login), $this->getDi()->view->escape($user->name_f), $this->getDi()->view->escape($user->name_l), $invoice->pk(), $invoice->public_id, amDatetime($payment->dattm), $this->getDi()->view->escape($payment->receipt_id), $this->getDi()->view->escape(Am_Currency::render($payment->amount)), $this->getDi()->view->escape(Am_Currency::render($payment->discount))); } //100% discount if (!$payments) { try { $user = Am_Di::getInstance()->userTable->load($invoice->user_id); $ret[] = sprintf($tpl, $this->getDi()->view->escape($user->login), $this->getDi()->view->escape($user->name_f), $this->getDi()->view->escape($user->name_l), $invoice->pk(), $invoice->public_id, amDatetime($invoice->tm_started), '–', $this->getDi()->view->escape(Am_Currency::render(0)), ___('100% discount')); } catch (Am_Exception_Db_NotFound $e) { $this->getDi()->errorLogTable->logException($e); } } } $out .= implode("\n", $ret); return $out ? sprintf($wrap, $out) : $out; }
public function renderCommAmount($record, $field, $grid) { return sprintf('<td style="text-align:right"><strong>%s</strong></td>', ($record->record_type == AffCommission::VOID ? '- ' : '') . Am_Currency::render($record->amount)); }
public function getDescription() { return ___('spent %s %s', $this->op, Am_Currency::render($this->val)); }
function renderConditions() { $ret = array(); foreach ($this->getConditions() as $conditionType => $vars) { switch ($conditionType) { case self::COND_AFF_ITEMS_COUNT: $ret[] = ___("affiliate generated %d item sales last %d days", $vars['count'], $vars['days']); break; case self::COND_AFF_SALES_COUNT: $ret[] = ___("affiliate generated %d sales last %d days", $vars['count'], $vars['days']); break; case self::COND_AFF_SALES_AMOUNT: $ret[] = ___("affiliate generated %d%s in commissions last %d days", $vars['count'], Am_Currency::getDefault(), $vars['days']); break; case self::COND_AFF_GROUP_ID: $v = array(); foreach ($this->getDi()->userGroupTable->loadIds((array) $vars) as $group) { $v[] = $group->title; } $ret[] = ___("affiliate group IN (%s)", implode(", ", $v)); break; case self::COND_PRODUCT_ID: $v = array(); foreach ($this->getDi()->productTable->loadIds((array) $vars) as $product) { $v[] = $product->title; } $ret[] = ___("products IN (%s)", implode(", ", $v)); break; case self::COND_PRODUCT_CATEGORY_ID: $v = array(); foreach ($this->getDi()->productCategoryTable->loadIds((array) $vars) as $product) { $v[] = $product->title; } $ret[] = ___("product category IN (%s)", implode(", ", $v)); break; case self::COND_COUPON: $txt = ''; switch ($vars['type']) { case 'any': $txt = $vars['used'] ? ___('Used Any Coupon') : ___("Did't Use Any Coupon"); break; case 'coupon': $text = $vars['used'] ? ___('Used Coupon with Code: %s', $vars['code']) : ___("Did't Use Coupon with Code: %s", $vars['code']); break; case 'batch': $options = $this->getDi()->couponBatchTable->getOptions(false); $txt = $vars['used'] ? ___('Used Coupon from Batch: %s', $options[$vars['batch_id']]) : ___("Did't Use Coupon from Batch: %s", $options[$vars['batch_id']]); break; } $ret[] = $txt; break; case self::COND_PAYSYS_ID: $ret[] = ___("paysystem IN (%s)", implode(', ', (array) $vars)); break; default: return false; } } return implode(" AND ", $ret); }
public function keywordsAction() { $ds = new Am_Query($this->getDi()->affKeywordTable); $ds->addField('t.`value`', 'keyword'); $ds->addField('count(clicks.log_id)', 'clicks_count'); $ds->addField('count(distinct leads.user_id)', 'leads_count'); $ds->addField('sum(if(commissions.record_type="commission", 1, 0))', 'sales_count'); $ds->addField('sum(if(commissions.record_type="commission", amount, -amount))', 'sales_amount'); $ds->addWhere('t.aff_id=?', $this->getDi()->auth->getUserId()); $ds->leftJoin('?_aff_click', 'clicks', 't.keyword_id = clicks.keyword_id'); $ds->leftJoin('?_aff_commission', 'commissions', 't.keyword_id = commissions.keyword_id'); $ds->leftJoin('?_aff_lead', 'leads', 't.keyword_id = leads.keyword_id'); $ds->groupBy('keyword_id'); $grid = new Am_Grid_ReadOnly('_aff_keywords', 'Keywords', $ds, $this->getRequest(), $this->getView()); $grid->addField('keyword', ___('Keyword')); $grid->addField('clicks_count', ___('Clicks')); $grid->addField('leads_count', ___('Leads')); $grid->addField('sales_count', ___('Sales')); $grid->addField('sales_amount', ___('Commissions'))->setRenderFunction(function ($record) { return "<td>" . Am_Currency::render($record->sales_amount) . "</td>"; }); $grid->runWithLayout('aff/keywords.phtml'); }
function doWork() { foreach ($this->groups as $list) { $byDate = array(); $totals = array(); // totals by date $coupon = null; $cancelled = null; $invoice = null; foreach ($list as $p) { $d = date('Y-m-d', strtotime($p['tm_added'])); $byDate[$d][] = $p; @($totals[$d] += $p['amount']); if (!empty($p['data'][0]['coupon'])) { $coupon = $p['data'][0]['coupon']; } if (!empty($p['data']['CANCELLED_AT'])) { $cancelled = date('Y-m-d H:i:s', strtotime($p['data']['CANCELLED_AT'])); } elseif (@$p['data']['CANCELLED']) { $cancelled = date('Y-m-d H:i:s', time()); } } if (count($list) == 1 && !$list[0]['data']['beanstream_rbaccountid'] && ($rbAccountId = $this->findRbAccountId($list[0]))) { $invoice = $this->getDi()->invoiceTable->findFirstByData('rb-account-id', $rbAccountId); } if (!$invoice) { $invoice = $this->getDi()->invoiceRecord; $invoice->user_id = $this->user->pk(); $pidItems = array(); foreach ($list as $p) { $pid = $p['product_id']; if (@$pidItems[$pid]) { continue; } $pidItems[$pid] = 1; $newP = $this->_translateProduct($pid); if ($newP) { $pr = Am_Di::getInstance()->productTable->load($newP); $item = $invoice->createItem($pr); if (empty($invoice->first_period)) { $invoice->first_period = $pr->getBillingPlan()->first_period; } } else { $item = $invoice->createItem(new ImportedProduct($pid)); $invoice->first_period = '1d'; } $item->add(1); $item->_calculateTotal(); $invoice->addItem($item); } if (!is_null($coupon)) { $invoice->setCouponCode($coupon); $invoice->validateCoupon(); } $invoice->currency = $item->currency ? $item->currency : Am_Currency::getDefault(); $invoice->calculate(); $invoice->paysys_id = $this->paysys_id; $invoice->tm_added = $list[0]['tm_added']; $invoice->tm_started = $list[0]['tm_completed']; $invoice->public_id = $list[0]['payment_id']; $invoice->first_total = current($totals); if ($invoice->rebill_times) { // Recurring if ($cancelled) { $invoice->tm_cancelled = $cancelled; $invoice->status = Invoice::RECURRING_CANCELLED; } else { $invoice->status = Invoice::RECURRING_ACTIVE; } } else { $invoice->status = Invoice::PAID; } foreach ($list as $p) { $pidlist[] = $p['payment_id']; } $invoice->data()->set('am3:id', implode(',', $pidlist)); if (empty($invoice->currency)) { $invoice->currency = Am_Currency::getDefault(); } //REQUIRED PART TO IMPORT RECURRING SUBCRIPTIONS if (@$p['data']['beanstream_rbaccountid']) { $invoice->data()->set('rb-account-id', $p['data']['beanstream_rbaccountid']); } $invoice->insert(); } // insert payments and access foreach ($list as $p) { $newP = $this->_translateProduct($p['product_id']); if (empty($p['data']['ORIG_ID'])) { $payment = $this->getDi()->invoicePaymentRecord; $payment->user_id = $this->user->user_id; $payment->currency = $invoice->currency; $payment->invoice_id = $invoice->pk(); $payment->invoice_public_id = $invoice->public_id; if (count($list) == 1) { $payment->amount = $p['amount']; } elseif ($p['data']['BASKET_PRICES']) { $payment->amount = array_sum($p['data']['BASKET_PRICES']); } else { $payment->amount = 0; foreach ($list as $pp) { if (@$p['data']['ORIG_ID'] == $p['payment_id']) { $payment->amount += $pp['amount']; } } } $payment->paysys_id = $this->paysys_id; $payment->dattm = $p['tm_completed']; $payment->receipt_id = $p['receipt_id']; $payment->transaction_id = $p['receipt_id'] . '-import-' . mt_rand(10000, 99999) . '-' . intval($p['payment_id']); $payment->insert(); $this->getDi()->db->query("INSERT INTO ?_data SET\n `table`='invoice_payment',`id`=?d,`key`='am3:id',`value`=?", $payment->pk(), $p['payment_id']); } if ($newP) { $a = $this->getDi()->accessRecord; $a->setDisableHooks(); $a->user_id = $this->user->user_id; $a->begin_date = $p['begin_date']; $a->expire_date = $p['expire_date']; $a->invoice_id = $invoice->pk(); $a->invoice_payment_id = $payment->pk(); $a->product_id = $newP; $a->insert(); } } } }
function initElements() { $this->addElement('text', 'site_title', array('class' => 'el-wide'), array('help-id' => '#Setup.2FEdit_Site_Title'))->setLabel(___('Site Title')); $this->addElement('static', null, null, array('help-id' => '#Root_URL_and_License_Key'))->setContent('<a href="' . Am_Controller::escape(REL_ROOT_URL) . '/admin-license" target="_top" class="link">' . ___('change') . '</a>')->setLabel(___('Root Url and License Keys')); $players = array('Flowplayer' => 'Flowplayer'); if (file_exists(ROOT_DIR . '/application/default/views/public/js/jwplayer/jwplayer.js')) { $players['JWPlayer'] = 'JWPlayer'; } $this->addSelect('video_player')->setId('video-player')->setLabel(___('Video Player'))->loadOptions($players)->toggleFrozen(count($players) == 1 ? true : false); $this->setDefault('video_player', 'Flowplayer'); $this->addText('flowplayer_license')->setId('video-player-Flowplayer')->setLabel(___("FlowPlayer License Key\nyou may get your key in %smembers area%s", '<a href="http://www.amember.com/amember/member?flowplayer_key=1" class="link">', '</a>'))->addRule('regex', ___('Value must be alphanumeric'), '/^[a-zA-Z0-9]*$/'); $this->addText('jwplayer_license')->setId('video-player-JWPlayer')->setLabel(___("JWPlayer License Key")); $this->addScript()->setScript(<<<CUT \$(function(){ \$('#video-player').change(function(){ \$('#video-player-Flowplayer').closest('.row').toggle(\$(this).val() == 'Flowplayer'); \$('#video-player-JWPlayer').closest('.row').toggle(\$(this).val() == 'JWPlayer'); }).change(); }) CUT ); $this->addElement('select', 'theme', null, array('help-id' => '#Setup.2FEdit_User_Pages_Theme'))->setLabel(___('User Pages Theme'))->loadOptions(Am_View::getThemes('user')); $this->addElement('select', 'admin_theme', null, array('help-id' => '#Setup.2FEdit_Admin_Pages_Theme'))->setLabel(___('Admin Pages Theme'))->loadOptions(Am_View::getThemes('admin')); $tax_plugins = array('global-tax' => ___('Global Tax'), 'regional' => ___('Regional Tax'), 'vat' => ___('EU VAT'), 'vat2015' => ___('EU VAT (New Rules 2015)'), 'gst' => ___('GST (Inclusive Tax)')); foreach (Am_Di::getInstance()->plugins_tax->getAvailable() as $plugin) { if (!isset($tax_plugins[$plugin])) { $tax_plugins[$plugin] = ucwords(str_replace("-", ' ', $plugin)); } } $this->addSelect('plugins.tax', array('size' => 1))->setLabel(___('Tax'))->loadOptions(array('' => ___('No Tax')) + $tax_plugins); $fs = $this->addElement('fieldset', '##02')->setLabel(___('Signup Form Configuration')); // $this->addElement('advcheckbox', 'generate_login') // ->setLabel(___('Generate Login', 'should aMember generate username for customer?')); $this->setDefault('login_min_length', 5); $this->setDefault('login_max_length', 16); $loginLen = $fs->addGroup(null, null, array('help-id' => '#Setup.2FEdit_Username_Rules'))->setLabel(___('Username Length')); $loginLen->addInteger('login_min_length', array('size' => 3))->setLabel('min'); $loginLen->addStatic('')->setContent(' — '); $loginLen->addInteger('login_max_length', array('size' => 3))->setLabel('max'); $fs->addElement('advcheckbox', 'login_disallow_spaces', null, array('help-id' => '#Setup.2FEdit_Username_Rules'))->setLabel(___('Do not Allow Spaces in Username')); $fs->addElement('advcheckbox', 'login_dont_lowercase', null, array('help-id' => '#Setup.2FEdit_Username_Rules'))->setLabel(___("Do not Lowercase Username\n" . "by default, aMember automatically lowercases entered username\n" . "here you can disable this function")); // $fs->addElement('advcheckbox', 'generate_pass') // ->setLabel(___('Generate Password', 'should aMember generate password for customer?')); // $this->setDefault('pass_min_length', 6); $this->setDefault('pass_max_length', 25); $passLen = $fs->addGroup(null, null, array('help-id' => '#Setup.2FEdit_Password_Length'))->setLabel(___('Password Length')); $passLen->addInteger('pass_min_length', array('size' => 3))->setLabel('min'); $passLen->addStatic('')->setContent(' — '); $passLen->addInteger('pass_max_length', array('size' => 3))->setLabel('max'); $fs->addAdvCheckbox('require_strong_password')->setLabel(___("Require Strong Password\n" . 'password should contain at least 2 capital letters, 2 or more numbers and 2 or more special chars')); $fs = $this->addElement('fieldset', '##03')->setLabel(___('Miscellaneous')); $this->setDefault('admin.records-on-page', 10); $fs->addElement('text', 'admin.records-on-page')->setLabel(___('Records per Page (for grids)')); $fs->addAdvCheckbox('disable_rte')->setLabel(___('Disable Visual HTML Editor')); $this->setDefault('currency', 'USD'); $currency = $fs->addElement('select', 'currency', array('size' => 1, 'class' => 'am-combobox'), array('help-id' => '#Set_Up.2FEdit_Base_Currency'))->setLabel(___("Base Currency\n" . "base currency to be used for reports and affiliate commission.\n" . "It could not be changed if there are any invoices in database.\n" . "You can edit exchange rate %shere%s", '<a class="link" href="' . REL_ROOT_URL . '/admin-currency-exchange">', '</a>'))->loadOptions(Am_Currency::getFullList()); if (Am_Di::getInstance()->db->selectCell("SELECT COUNT(*) FROM ?_invoice")) { $currency->toggleFrozen(true); } $this->addSelect('404_page')->setLabel(___("Page Not Found (404)\n" . "%sthis page will be public and do not require any login/password%s\n" . 'you can create new pages %shere%s', '<strong>', '</strong>', '<a class="link" href="' . REL_ROOT_URL . '/default/admin-content/p/pages/index' . '">', '</a>'))->loadOptions(array('' => ___('Default Not Found Page')) + Am_Di::getInstance()->db->selectCol("SELECT page_id AS ?, title FROM ?_page", DBSIMPLE_ARRAY_KEY)); }
function getSupportedCurrencies() { return array_keys(Am_Currency::getFullList()); }
protected function addSub(Am_Record $user, $lineParsed) { $user_id = $user->pk(); $product = $this->getDi()->productTable->load($this->getImportField('product_id', self::FIELD_TYPE_SUBSCRIPTION)->getValue($lineParsed), false); if (!$product) { return; } $invoice = $this->getDi()->invoiceRecord; $invoice->user_id = $user_id; $invoice->paysys_id = $this->getImportField('paysys_id', self::FIELD_TYPE_SUBSCRIPTION)->getValue($lineParsed); $invoice->currency = Am_Currency::getDefault(); $invoice->status = Invoice::PAID; $invoice->add($product); $items = $invoice->getItems(); $items[0]->first_total = $this->getImportField('amount', self::FIELD_TYPE_SUBSCRIPTION)->getValue($lineParsed); $invoice->calculate(); $invoice->insert(); if ($external_id = $this->getImportField('invoice_external_id', self::FIELD_TYPE_SUBSCRIPTION)->getValue($lineParsed)) { $invoice->data()->set('external_id', $external_id)->update(); } $payment = null; if ($amount = $this->getImportField('amount', self::FIELD_TYPE_SUBSCRIPTION)->getValue($lineParsed)) { $payment = $this->getDi()->invoicePaymentRecord; $payment->amount = $amount; $payment->user_id = $user_id; $payment->paysys_id = $this->getImportField('paysys_id', self::FIELD_TYPE_SUBSCRIPTION)->getValue($lineParsed); $payment->invoice_id = $invoice->pk(); $payment->receipt_id = $this->getImportField('receipt_id', self::FIELD_TYPE_SUBSCRIPTION)->getValue($lineParsed); $payment->transaction_id = $this->getID(); $payment->currency = $invoice->currency; $payment->dattm = $this->getImportField('begin_date', self::FIELD_TYPE_SUBSCRIPTION)->getValue($lineParsed); if (empty($payment->dattm)) { $payment->dattm = $this->getDi()->sqlDateTime; // fallback to import time } $payment->save(); } $access = $this->getDi()->accessRecord; $access->begin_date = $this->getImportField('begin_date', self::FIELD_TYPE_SUBSCRIPTION)->getValue($lineParsed); $access->expire_date = $this->getImportField('expire_date', self::FIELD_TYPE_SUBSCRIPTION)->getValue($lineParsed); $access->user_id = $user_id; $access->product_id = $product->pk(); $access->invoice_id = $invoice->pk(); $access->invoice_payment_id = $payment ? $payment->pk() : null; $access->transaction_id = $this->getID(); $access->save(); }
function _getTax(InvoicePayment $p) { return Am_Currency::render($p->tax, $p->currency); }
public function renderOut(&$out) { $titles = array(); $sql = $this->ds->getSql(); $totals = array(); foreach ($this->fields as $field) { /* @var $field Am_Grid_Field */ $name = $field->getFieldName(); $stm = $this->stms[$name]; $titles['_' . $name] = $field->getFieldTitle(); $totals[] = sprintf('%s %s: <strong>%s</strong>', ___('Total'), $field->getFieldTitle(), Am_Currency::render(Am_Di::getInstance()->db->selectCell("select sum(total_qry.{$name}) from ({$sql} ) as total_qry"))); } $count = count($this->grid->getFields()); $tr = sprintf('<tr><td class="grid-total" colspan="%d">%s</td></td>', $count, implode(',', $totals)); $out = preg_replace('|(<tr>\\s*<th>)|', str_replace('$', '\\$', $tr) . '\\1', $out); }
public function run(Am_Paysystem_Result $result) { $subscriptionid = $this->invoice->data()->get(Am_Paysystem_Epay::SUBSCRIPTIONID); $req = $this->plugin->APIRequest('subscription', 'authorize', $vars = array('merchantnumber' => $this->plugin->getConfig('id'), 'subscriptionid' => $subscriptionid, 'orderid' => $this->invoice->public_id . "-" . $this->invoice->getPaymentsCount(), 'amount' => $this->invoice->second_total * 100, 'currency' => Am_Currency::getNumericCode($this->invoice->currency), 'instantcapture' => 1, 'description' => 'Recurring payment for invoice ' . $this->invoice->public_id, 'email' => $this->invoice->getEmail(), 'ipaddress' => $this->invoice->getUser()->remote_addr)); $log = $this->getInvoiceLog(); $log->add(print_r($vars, true)); $this->ret = $this->plugin->getResponseXML($req); $log->add(print_r($this->ret, true)); if ($this->ret->authorizeResponse->authorizeResult != 'true') { $result->setFailed(___("Payment failed") . ":" . $this->plugin->getEpayError($this->ret->authorizeResponse->epayresponse)); } else { $result->setSuccess($this); $this->processValidated(); } }
public function renderOut(&$out) { $totals = array(); $totals[] = sprintf('%s %s: <strong>%s</strong>', ___('Total'), ___('To Pay'), Am_Currency::render(Am_Di::getInstance()->db->selectCell("SELECT SUM(amount) from ?_aff_payout_detail"))); $totals[] = sprintf('%s %s: <strong>%s</strong>', ___('Total'), ___('Paid'), Am_Currency::render(Am_Di::getInstance()->db->selectCell("SELECT SUM(amount) from ?_aff_payout_detail where is_paid > 0"))); $count = count($this->grid->getFields()); $tr = sprintf('<tr><td class="grid-total" colspan="%d">%s</td></td>', $count, implode(',', $totals)); $out = preg_replace('|(<tr>\\s*<th>)|', str_replace('$', '\\$', $tr) . '\\1', $out); }
public function createConfigForm(Am_Grid_Editable $grid) { $form = new Am_Form_Admin(); $record = $grid->getRecord($grid->getCurrentAction()); if (empty($record->type)) { $record->type = null; } if (empty($record->tier)) { $record->tier = 0; } $globalOptions = AffCommissionRule::getTypes(); $record->type && !isset($globalOptions[$record->type]) && ($globalOptions[$record->type] = $record->getTypeTitle()); $cb = $form->addSelect('type')->setLabel('Type')->loadOptions($globalOptions); if ($record->isGlobal()) { $cb->toggleFrozen(true); } $form->addScript()->setScript(<<<CUT \$(function(){ \$("select#type-0").change(function(){ var val = \$(this).val(); \$("fieldset#multiplier").toggle(val == 'multi'); \$("fieldset#commission").toggle(val != 'multi'); var checked = val.match(/^global-/); \$("#conditions").toggle(!checked); \$("#sort_order-0").closest(".row").toggle(!checked); }).change(); \$("#condition-select").change(function(){ var val = \$(this).val(); \$(this.options[this.selectedIndex]).prop("disabled", true); this.selectedIndex = 0; \$('input[name="_conditions_status[' + val + ']"]').val(1); \$('#row-'+val).show(); }); \$("#conditions .row").not("#row-condition-select").each(function(){ var val = /row-(.*)/i.exec(this.id).pop(); if (!\$('input[name="_conditions_status[' + val + ']"]').val()) { \$(this).hide(); } else { \$("#condition-select option[value='"+val+"']").prop("disabled", true); } \$(this).find(".element-title").append(" <a href='javascript:' class='hide-row'>X</a> "); }); \$(document).on('click',"a.hide-row",function(){ var row = \$(this).closest(".row"); var id = row.hide().attr("id"); var val = /row-(.*)/i.exec(id).pop(); \$('input[name="_conditions_status[' + val + ']"]').val(0); \$("#condition-select option[value='"+val+"']").prop("disabled", false); }); \$('#used-type').change(function(){ \$('#used-batch_id, #used-code').hide(); switch (\$(this).val()) { case 'batch' : \$('#used-batch_id').show(); break; case 'coupon' : \$('#used-code').show(); break; } }).change() }); CUT ); $comment = $form->addText('comment', array('size' => 40))->setLabel('Rule title - for your own reference'); if ($record->isGlobal()) { $comment->toggleFrozen(true); } else { $comment->addRule('required', 'This field is required'); } if (!$record->isGlobal()) { $form->addInteger('sort_order')->setLabel('Sort order - rules with lesser values executed first'); } if (!$record->isGlobal()) { $set = $form->addFieldset('', array('id' => 'conditions'))->setLabel('Conditions'); $set->addSelect('', array('id' => 'condition-select'))->setLabel('Add Condition')->loadOptions(array('' => ___('Select Condition...'), 'first_time' => ___('First Time Purchase of Product'), 'coupon' => ___('By Used Coupon'), 'paysys_id' => ___('By Used Payment System'), 'product_id' => ___('By Product'), 'product_category_id' => ___('By Product Category'), 'aff_group_id' => ___('By Affiliate Group Id'), 'aff_sales_count' => ___('By Affiliate Sales Count'), 'aff_items_count' => ___('By Affiliate Item Sales Count'), 'aff_sales_amount' => ___('By Affiliate Sales Amount'), 'aff_product_id' => ___('By Affiliate Active Product'), 'aff_product_category_id' => ___('By Affiliate Active Product Category'))); $set->addHidden('_conditions_status[product_id]'); $set->addMagicSelect('_conditions[product_id]', array('id' => 'product_id'))->setLabel(___("This rule is for particular products\n" . 'if none specified, rule works for all products'))->loadOptions(Am_Di::getInstance()->productTable->getOptions()); $set->addHidden('_conditions_status[product_category_id]'); $el = $set->addMagicSelect('_conditions[product_category_id]', array('id' => 'product_category_id'))->setLabel(___("This rule is for particular product categories\n" . "if none specified, rule works for all product categories")); $el->loadOptions(Am_Di::getInstance()->productCategoryTable->getAdminSelectOptions()); $set->addHidden('_conditions_status[aff_group_id]'); $el = $set->addMagicSelect('_conditions[aff_group_id]', array('id' => 'aff_group_id'))->setLabel(___("This rule is for particular affiliate groups\n" . "you can add user groups and assign it to customers in User editing form")); $el->loadOptions(Am_Di::getInstance()->userGroupTable->getSelectOptions()); $set->addHidden('_conditions_status[aff_sales_count]'); $gr = $set->addGroup('_conditions[aff_sales_count]', array('id' => 'aff_sales_count'))->setLabel(___("Affiliate sales count\n" . "trigger this commission if affiliate made more than ... sales within ... days before the current date\n" . "(only count of new invoices is calculated)")); $gr->addStatic()->setContent('use only if affiliate referred '); $gr->addInteger('count', array('size' => 4)); $gr->addStatic()->setContent(' invoices within last '); $gr->addInteger('days', array('size' => 4)); $gr->addStatic()->setContent(' days'); $set->addHidden('_conditions_status[aff_items_count]'); $gr = $set->addGroup('_conditions[aff_items_count]', array('id' => 'aff_items_count'))->setLabel(___("Affiliate items count\n" . "trigger this commission if affiliate made more than ... item sales within ... days before the current date\n" . "(only count of items in new invoices is calculated")); $gr->addStatic()->setContent('use only if affiliate made '); $gr->addInteger('count', array('size' => 4)); $gr->addStatic()->setContent(' item sales within last '); $gr->addInteger('days', array('size' => 4)); $gr->addStatic()->setContent(' days'); $set->addHidden('_conditions_status[aff_sales_amount]'); $gr = $set->addGroup('_conditions[aff_sales_amount]', array('id' => 'aff_sales_amount'))->setLabel(___("Affiliate sales amount\n" . "trigger this commission if affiliate made more than ... sales within ... days before the current date\n" . "(only new invoices calculated)")); $gr->addStatic()->setContent('use only if affiliate made '); $gr->addInteger('count', array('size' => 4)); $gr->addStatic()->setContent(' ' . Am_Currency::getDefault() . ' in commissions within last '); $gr->addInteger('days', array('size' => 4)); $gr->addStatic()->setContent(' days'); $set->addHidden('_conditions_status[coupon]'); $gr = $set->addGroup('_conditions[coupon]', array('id' => 'coupon'))->setLabel(___('Used coupon')); $gr->setSeparator(' '); $gr->addSelect('used')->loadOptions(array('1' => 'Used', '0' => "Didn't Use")); $gr->addSelect('type')->setId('used-type')->loadOptions(array('any' => ___('Any Coupon'), 'batch' => ___("Coupon From Batch"), 'coupon' => ___("Specific Coupon"))); $gr->addSelect('batch_id')->setId('used-batch_id')->loadOptions($this->getDi()->couponBatchTable->getOptions()); $gr->addText('code', array('size' => 10))->setId('used-code'); $set->addHidden('_conditions_status[paysys_id]'); $set->addMagicSelect('_conditions[paysys_id]', array('id' => 'paysys_id'))->setLabel(___('This rule is for particular payment system'))->loadOptions(Am_Di::getInstance()->paysystemList->getOptions()); $set->addHidden('_conditions_status[first_time]'); $set->addStatic('_conditions[first_time]', array('id' => 'first_time'))->setLabel(___("First Time Purchase of Product"))->setContent("<div><strong>✓</strong></div>"); $set->addHidden('_conditions_status[aff_product_id]'); $set->addMagicSelect('_conditions[aff_product_id]', array('id' => 'aff_product_id'))->setLabel(___("Apply this rule if affiliate has active access to"))->loadOptions(Am_Di::getInstance()->productTable->getOptions()); $set->addHidden('_conditions_status[aff_product_category_id]'); $el = $set->addMagicSelect('_conditions[aff_product_category_id]', array('id' => 'aff_product_category_id'))->setLabel(___("Apply this rule if affiliate has active access to")); $el->loadOptions(Am_Di::getInstance()->productCategoryTable->getAdminSelectOptions()); } $set = $form->addFieldset('', array('id' => 'commission'))->setLabel('Commission'); if ($record->tier == 0) { $set->addElement(new Am_Form_Element_AffCommissionSize(null, null, 'first_payment'))->setLabel(___("Commission for First Payment\ncalculated for first payment in each invoice")); $set->addElement(new Am_Form_Element_AffCommissionSize(null, null, 'recurring'))->setLabel(___("Commission for Rebills")); $group = $set->addGroup('')->setLabel(___("Commission for Free Signup\ncalculated for first customer invoice only")); $group->addText('free_signup_c', array('size' => 5)); $group->addStatic()->setContent(' ' . Am_Currency::getDefault()); //->addRule('gte', 'Value must be a valid number > 0, or empty (no text)', 0); } else { $set->addText('first_payment_c')->setLabel(___("Commission\n% of commission received by referred affiliate")); } if (!$record->isGlobal()) { $set = $form->addFieldset('', array('id' => 'multiplier'))->setLabel('Multipier'); $set->addText('multi', array('size' => 5, 'placeholder' => '1.0'))->setLabel(___("Multiply commission calculated by the following rules\n" . "to number specified in this field. To keep commission untouched, enter 1 or delete this rule")); //->addRule('gt', 'Values must be greater than 0.0', 0.0); } return $form; }