예제 #1
0
 function process(Am_Form $f)
 {
     $vars = $f->getValue();
     $user = Am_Di::getInstance()->userTable->findFirstByLogin($vars['user']);
     if (!$user) {
         list($el) = $f->getElementsByName('user');
         $el->setError(___('User %s not found', $vars['user']));
         return false;
     }
     $item = $this->grid->getRecord();
     $view = Am_Di::getInstance()->view;
     $view->title = ___('Preview of Notification');
     $view->content = $item->render($view, $user);
     echo $view->render('layout.phtml');
     exit;
 }
 function process(Am_Form $f)
 {
     $vars = $f->getValue();
     $user = Am_Di::getInstance()->userTable->findFirstByLogin($vars['user']);
     if (!$user) {
         list($el) = $f->getElementsByName('user');
         $el->setError(___('User %s not found', $vars['user']));
         return false;
     }
     $aff = Am_Di::getInstance()->userTable->findFirstByLogin($vars['aff']);
     if (!$aff) {
         list($el) = $f->getElementsByName('aff');
         $el->setError(___('Affiliate %s not found', $vars['user']));
         return false;
     }
     $couponAff = null;
     if ($vars['coupon']) {
         $coupon = Am_DI::getInstance()->couponTable->findFirstByCode($vars['coupon']);
         if ($coupon && ($coupon->aff_id || $coupon->getBatch()->aff_id)) {
             $couponAff = Am_Di::getInstance()->userTable->load($coupon->aff_id ? $coupon->aff_id : $coupon->getBatch()->aff_id, false);
         }
     }
     /* @var $invoice Invoice */
     $invoice = Am_Di::getInstance()->invoiceTable->createRecord();
     $invoice->setUser($user);
     if ($vars['coupon']) {
         $invoice->setCouponCode($vars['coupon']);
         $error = $invoice->validateCoupon();
         if ($error) {
             throw new Am_Exception_InputError($error);
         }
     }
     $user->aff_id = $aff->pk();
     foreach ($vars['product_id'] as $plan_id => $qty) {
         $p = Am_Di::getInstance()->billingPlanTable->load($plan_id);
         $pr = $p->getProduct();
         $invoice->add($pr, $qty);
     }
     $invoice->calculate();
     $invoice->setPaysystem($vars['paysys_id'], false);
     $invoice->invoice_id = '00000';
     $invoice->public_id = 'TEST';
     $invoice->tm_added = sqlTime('now');
     echo "<pre>";
     echo $invoice->render();
     echo "\nBilling Terms: " . $invoice->getTerms() . "\n" . str_repeat("-", 70) . "\n";
     $helper = new Am_View_Helper_UserUrl();
     $helper->setView(new Am_View());
     printf("User Ordering the subscription: <a target='_blank' class='link' href='%s'>%d/%s &quot;%s&quot; &lt;%s&gt</a>\n", $helper->userUrl($user->pk()), $user->pk(), Am_Controller::escape($user->login), Am_Controller::escape($user->name_f . ' ' . $user->name_l), Am_Controller::escape($user->email));
     printf("Reffered Affiliate: <a target='_blank' class='link' href='%s'>%d/%s &quot;%s&quot; &lt;%s&gt</a>\n", $helper->userUrl($aff->pk()), $aff->pk(), Am_Controller::escape($aff->login), Am_Controller::escape($aff->name_f . ' ' . $aff->name_l), Am_Controller::escape($aff->email));
     if ($couponAff) {
         printf("Affiliate Detected by Coupon (will get commision): <a target='_blank' class='link' href='%s'>%d/%s &quot;%s&quot; &lt;%s&gt</a>\n", $helper->userUrl($couponAff->pk()), $couponAff->pk(), Am_Controller::escape($couponAff->login), Am_Controller::escape($couponAff->name_f . ' ' . $couponAff->name_l), Am_Controller::escape($couponAff->email));
     }
     $max_tier = Am_Di::getInstance()->affCommissionRuleTable->getMaxTier();
     //COMMISSION FOR FREE SIGNUP
     if (!(double) $invoice->first_total && !(double) $invoice->second_total && $vars['is_first']) {
         echo "\n<strong>FREE SIGNUP</strong>:\n";
         list($item, ) = $invoice->getItems();
         echo sprintf("* ITEM: %s\n", Am_Controller::escape($item->item_title));
         foreach (Am_Di::getInstance()->affCommissionRuleTable->findRules($invoice, $item, $aff, 0, 0) as $rule) {
             echo $rule->render('*   ');
         }
         $to_pay = Am_Di::getInstance()->affCommissionRuleTable->calculate($invoice, $item, $aff, 0, 0);
         echo "* AFFILIATE WILL GET FOR THIS ITEM: " . Am_Currency::render($to_pay) . "\n";
         for ($i = 1; $i <= $max_tier; $i++) {
             $to_pay = Am_Di::getInstance()->affCommissionRuleTable->calculate($invoice, $item, $aff, 0, $i, $to_pay);
             $tier = $i + 1;
             echo "* {$tier}-TIER AFFILIATE WILL GET FOR THIS ITEM: " . Am_Currency::render($to_pay) . "\n";
         }
         echo str_repeat("-", 70) . "\n";
     }
     //COMMISSION FOR FIRST PAYMENT
     $price_field = (double) $invoice->first_total ? 'first_total' : 'second_total';
     if ((double) $invoice->{$price_field}) {
         echo "\n<strong>FIRST PAYMENT ({$invoice->currency} {$invoice->{$price_field}})</strong>:\n";
         $payment = Am_Di::getInstance()->invoicePaymentTable->createRecord();
         $payment->invoice_id = @$invoice->invoice_id;
         $payment->dattm = sqlTime('now');
         $payment->amount = $invoice->{$price_field};
         echo str_repeat("-", 70) . "\n";
         foreach ($invoice->getItems() as $item) {
             if (!(double) $item->{$price_field}) {
                 continue;
             }
             //do not calculate commission for free items within invoice
             echo sprintf("* ITEM: %s ({$invoice->currency} {$item->{$price_field}})\n", Am_Controller::escape($item->item_title));
             foreach (Am_Di::getInstance()->affCommissionRuleTable->findRules($invoice, $item, $aff, 1, 0, $payment->dattm) as $rule) {
                 echo $rule->render('*   ');
             }
             $to_pay = Am_Di::getInstance()->affCommissionRuleTable->calculate($invoice, $item, $aff, 1, 0, $payment->amount, $payment->dattm);
             echo "* AFFILIATE WILL GET FOR THIS ITEM: <strong>" . Am_Currency::render($to_pay) . "</strong>\n";
             for ($i = 1; $i <= $max_tier; $i++) {
                 $to_pay = Am_Di::getInstance()->affCommissionRuleTable->calculate($invoice, $item, $aff, 1, $i, $to_pay, $payment->dattm);
                 $tier = $i + 1;
                 echo "* {$tier}-TIER AFFILIATE WILL GET FOR THIS ITEM: <strong>" . Am_Currency::render($to_pay) . "</strong>\n";
             }
             echo str_repeat("-", 70) . "\n";
         }
     }
     //COMMISSION FOR SECOND AND SUBSEQUENT PAYMENTS
     if ((double) $invoice->second_total) {
         echo "\n<strong>SECOND AND SUBSEQUENT PAYMENTS ({$invoice->second_total} {$invoice->currency})</strong>:\n";
         $payment = Am_Di::getInstance()->invoicePaymentTable->createRecord();
         $payment->invoice_id = @$invoice->invoice_id;
         $payment->dattm = sqlTime('now');
         $payment->amount = $invoice->second_total;
         echo str_repeat("-", 70) . "\n";
         foreach ($invoice->getItems() as $item) {
             if (!(double) $item->second_total) {
                 continue;
             }
             //do not calculate commission for free items within invoice
             echo sprintf("* ITEM:  %s ({$item->second_total} {$invoice->currency})\n", Am_Controller::escape($item->item_title));
             foreach (Am_Di::getInstance()->affCommissionRuleTable->findRules($invoice, $item, $aff, 2, 0, $payment->dattm) as $rule) {
                 echo $rule->render('*   ');
             }
             $to_pay = Am_Di::getInstance()->affCommissionRuleTable->calculate($invoice, $item, $aff, 2, 0, $payment->amount, $payment->dattm);
             echo "* AFFILIATE WILL GET FOR THIS ITEM: <strong>" . Am_Currency::render($to_pay) . "</strong>\n";
             for ($i = 1; $i <= $max_tier; $i++) {
                 $to_pay = Am_Di::getInstance()->affCommissionRuleTable->calculate($invoice, $item, $aff, 2, $i, $to_pay, $payment->dattm);
                 $tier = $i + 1;
                 echo "* {$tier}-TIER AFFILIATE WILL GET FOR THIS ITEM: <strong>" . Am_Currency::render($to_pay) . "</strong>\n";
             }
             echo str_repeat("-", 70) . "\n";
         }
     }
     echo "</pre>";
     return true;
 }
 function process(Am_Form $f)
 {
     $vars = $f->getValue();
     $user = Am_Di::getInstance()->userTable->findFirstByLogin($vars['user']);
     if (!$user) {
         list($el) = $f->getElementsByName('user');
         $el->setError(___('User %s not found', $vars['user']));
         return false;
     }
     $page = $this->grid->getRecord();
     echo $page->render(Am_Di::getInstance()->view, $user);
     exit;
 }
예제 #4
0
파일: epay.php 프로젝트: irovast/eyedock
 function renameElement(Am_Form $form, $from, $to)
 {
     foreach ($form->getElementsByName($from) as $el) {
         $el->setName($to);
     }
 }