Exemplo n.º 1
0
 function infoTabAction()
 {
     require_once APPLICATION_PATH . '/default/controllers/AdminUsersController.php';
     require_once 'Am/Report.php';
     require_once 'Am/Report/Standard.php';
     include_once APPLICATION_PATH . '/aff/library/Reports.php';
     $this->setActiveMenu('users-browse');
     $rs = new Am_Report_AffStats();
     $rs->setAffId($this->user_id);
     $rc = new Am_Report_AffClicks();
     $rc->setAffId($this->user_id);
     $form = $rs->getForm();
     if ($form->isSubmitted() && $form->validate()) {
         $rs->applyConfigForm($this->_request);
     } else {
         $rs->setInterval('-1 month', 'now')->setQuantity(new Am_Report_Quant_Day());
         $form->addDataSource(new Am_Request(array('start' => $rs->getStart(), 'stop' => $rs->getStop())));
     }
     $rc->setInterval($rs->getStart(), $rs->getStop())->setQuantity(clone $rs->getQuantity());
     $result = $rs->getReport();
     $rc->getReport($result);
     $this->view->form = $form;
     $this->view->form->setAction($this->_request->getRequestUri());
     $output = new Am_Report_Graph_Line($result);
     $output->setSize(600, 300);
     $this->view->report = $output->render();
     $this->view->result = $result;
     $this->view->display('admin/aff/info-tab.phtml');
 }
 function statsAction()
 {
     require_once 'Am/Report.php';
     require_once 'Am/Report/Standard.php';
     include_once APPLICATION_PATH . '/aff/library/Reports.php';
     if ($this->getDi()->config->get('aff.affiliate_can_view_details') && ($detailDate = $this->getFiltered('detailDate'))) {
         if (!preg_match('/^\\d{4}-\\d{2}-\\d{2}$/', $detailDate)) {
             throw new Am_Exception_InputError("Wrong date passed");
         }
         $c = 0;
         foreach ($this->getDi()->affCommissionTable->fetchByDate($detailDate, $this->user->user_id) as $c) {
             $c++;
             $p = $c->getPayment();
             if (!$p) {
                 continue;
             }
             $u = $p->getUser();
             $i = $p->getInvoice();
             $s = $this->escape($u->name_f . ' ' . $u->name_l . ' - ' . $i->getCurrency($c->amount));
             if ($c->record_type == AffCommission::VOID) {
                 $s = "<div style='color: red'>{$s} (void)</div>";
             }
             echo $s . "<br />\n";
         }
         if (!$c) {
             echo ___("No commissions on this date");
         }
         return;
     }
     $rs = new Am_Report_AffStats();
     $rs->setAffId($this->user->user_id);
     $rc = new Am_Report_AffClicks();
     $rc->setAffId($this->user->user_id);
     if (!$this->getInt('monthyear')) {
         $this->view->form = "";
         $firstDate[] = $this->getDi()->db->selectCell("SELECT MIN(date) FROM ?_aff_commission WHERE aff_id=?d", $this->user->user_id);
         $firstDate[] = current(explode(' ', $this->getDi()->db->selectCell("SELECT MIN(`time`) FROM ?_aff_click WHERE aff_id=?d", $this->user->user_id)));
         $rs->setInterval(min($firstDate), 'now')->setQuantity(new Am_Report_Quant_Month());
     } else {
         $ym = $this->getInt('monthyear');
         if (!$ym || strlen($ym) != 6) {
             $ym = date('Ym');
         }
         $start = mktime(0, 0, 0, substr($ym, 4, 2), 1, substr($ym, 0, 4));
         $rs->setInterval(date('Y-m-d 00:00:00', $start), date('Y-m-t 23:59:59', $start))->setQuantity(new Am_Report_Quant_Day());
     }
     $rc->setInterval($rs->getStart(), $rs->getStop())->setQuantity(clone $rs->getQuantity());
     $result = $rs->getReport();
     $rc->getReport($result);
     $output = new Am_Report_Graph_Line($result);
     $output->setSize(780, 300);
     $this->view->report = $output->render();
     $this->view->result = $result;
     $this->view->display('aff/stats.phtml');
 }
Exemplo n.º 3
0
 function statsAction()
 {
     require_once 'Am/Report.php';
     require_once 'Am/Report/Standard.php';
     include_once APPLICATION_PATH . '/aff/library/Reports.php';
     if ($this->getDi()->config->get('aff.affiliate_can_view_details') && ($detailDate = $this->getFiltered('detailDate'))) {
         if (!preg_match('/^\\d{4}-\\d{2}-\\d{2}$/', $detailDate)) {
             throw new Am_Exception_InputError("Wrong date passed");
         }
         $c = 0;
         foreach ($this->getDi()->affCommissionTable->fetchByDate($detailDate, $this->user->user_id) as $c) {
             $c++;
             $p = $c->getPayment();
             if (!$p) {
                 continue;
             }
             $u = $p->getUser();
             $i = $p->getInvoice();
             $product = $c->getProduct();
             $s = sprintf('%s (%s) &ndash; <strong>%s</strong>%s', $this->escape($u->name_f . '&nbsp;' . $u->name_l), ___($product->title), Am_Currency::render($c->amount), $c->tier ? sprintf(' (%d-tier)', $c->tier + 1) : '');
             if ($c->record_type == AffCommission::VOID) {
                 $s = "<div style='color: red'>{$s} (void)</div>";
             }
             echo $s . "<br />\n";
         }
         if (!$c) {
             echo ___('No commissions on this date');
         }
         return;
     }
     $rs = new Am_Report_AffStats();
     $rs->setAffId($this->user->user_id);
     $rc = new Am_Report_AffClicks();
     $rc->setAffId($this->user->user_id);
     $rn = new Am_Report_AffSales();
     $rn->setAffId($this->user->user_id);
     if (!$this->getInt('monthyear')) {
         $firstDate[] = $this->getDi()->db->selectCell("SELECT MIN(date) FROM ?_aff_commission WHERE aff_id=?d", $this->user->user_id);
         $firstDate[] = current(explode(' ', $this->getDi()->db->selectCell("SELECT MIN(`time`) FROM ?_aff_click WHERE aff_id=?d", $this->user->user_id)));
         $rs->setInterval(min($firstDate), 'now')->setQuantity(new Am_Report_Quant_Month());
     } else {
         $ym = $this->getInt('monthyear');
         if (!$ym || strlen($ym) != 6) {
             $ym = date('Ym');
         }
         $start = mktime(0, 0, 0, substr($ym, 4, 2), 1, substr($ym, 0, 4));
         $rs->setInterval(date('Y-m-d 00:00:00', $start), date('Y-m-t 23:59:59', $start))->setQuantity(new Am_Report_Quant_Day());
         $this->view->period = array(date('Y-m-d 00:00:00', $start), date('Y-m-t 23:59:59', $start));
     }
     $rc->setInterval($rs->getStart(), $rs->getStop())->setQuantity(clone $rs->getQuantity());
     $rn->setInterval($rs->getStart(), $rs->getStop())->setQuantity(clone $rs->getQuantity());
     $result = $rs->getReport();
     $rc->getReport($result);
     $rn->getReport($result);
     $output = new Am_Report_Graph_Line($result);
     $output->setSize('100%', 300);
     $this->view->report = $output->render();
     /* extract data from report to show it in view */
     $rows = array();
     $totals = array();
     $lines = $result->getLines();
     foreach ($result->getPointsWithValues() as $r) {
         /* @var $r Am_Report_Point */
         if ($result->getQuantity()->getId() == 'month') {
             $hasValue = false;
             foreach ($lines as $line) {
                 if ($r->getValue($line->getKey())) {
                     $hasValue = true;
                     break;
                 }
             }
             $href = $hasValue ? $this->view->url(array("monthyear" => $r->getKey())) : '';
         } elseif ($this->getModule()->getConfig('affiliate_can_view_details')) {
             $href = "javascript: showAffDetails('{$r->getKey()}')";
         } else {
             $href = "";
         }
         $rows[$r->getKey()]['date'] = $r->getLabel();
         $rows[$r->getKey()]['date_href'] = $href;
         foreach ($lines as $i => $line) {
             list($start, $stop) = $result->getQuantity()->getStartStop($r->getKey());
             $href = $r->getValue($line->getKey()) > 0 ? sprintf("javascript:affDetail('%s', '%s', '%s')", $start, $stop, $r->getLabel()) : null;
             $rows[$r->getKey()][$line->getKey() . '_href'] = $href;
             $rows[$r->getKey()][$line->getKey()] = $r->getValue($line->getKey());
             $totals[$line->getKey()] = @$totals[$line->getKey()] + $r->getValue($line->getKey());
         }
     }
     $this->view->totals = $totals;
     $this->view->rows = $rows;
     $this->view->result = $result;
     $this->view->display('aff/stats.phtml');
 }
Exemplo n.º 4
0
 public function renderWidgetReport(Am_View $view, $config = null, $invokeArgs = array())
 {
     require_once 'Am/Report.php';
     require_once 'Am/Report/Standard.php';
     $view->enableReports();
     /* @var $savedReport SavedReport */
     $savedReport = $invokeArgs['savedReport'];
     $request = new Am_Request(unserialize($savedReport->request));
     $r = Am_Report_Abstract::createById($savedReport->report_id);
     $r->applyConfigForm($request);
     $result = $r->getReport();
     $result->setTitle($savedReport->title);
     $type = is_null($config) ? 'graph-line' : $config['type'];
     switch ($type) {
         case 'graph-line':
             $output = new Am_Report_Graph_Line($result);
             $output->setSize('100%', 250);
             break;
         case 'graph-bar':
             $output = new Am_Report_Graph_Bar($result);
             $output->setSize('100%', 250);
             break;
         case 'table':
             $output = new Am_Report_Table($result);
             break;
         default:
             throw new Am_Exception_InputError(___('Unknown report display type [%s]', $type));
     }
     return sprintf('<h2>%s</h2><div class="admin-index-report-wrapper"><div class="admin-index-report report-%s">%s</div></div>', $savedReport->title, $savedReport->report_id, $output->render());
 }