static function getTotalAllowedChildItems($gids, $metaUser, $list = array()) { $groups = ItemGroupHandler::getChildren($gids, 'group'); if (!empty($groups)) { foreach ($groups as $groupid) { $group = new ItemGroup(); $group->load($groupid); if (!$group->checkVisibility($metaUser)) { continue; } if (!empty($group->params['reveal_child_items']) && empty($group->params['symlink'])) { $list = ItemGroupHandler::getTotalAllowedChildItems($groupid, $metaUser, $list); } else { if (ItemGroupHandler::hasVisibleChildren($group, $metaUser)) { $list[] = ItemGroupHandler::getGroupListItem($group); } } } } $items = ItemGroupHandler::getChildren($gids, 'item'); if (!empty($items)) { foreach ($items as $itemid) { $plan = new SubscriptionPlan(); $plan->load($itemid); if (!$plan->checkVisibility($metaUser)) { continue; } $list[] = ItemGroupHandler::getItemListItem($plan); } } return $list; }
public function index() { if (!empty($this->state->filter->group)) { $subselect = ItemGroupHandler::getChildren($this->state->filter->group, 'item'); $this->addConstraint('id IN (' . implode(',', $subselect) . ')'); } else { $subselect = array(); } $nav = $this->getPagination(); // get the subset (based on limits) of records $rows = SubscriptionPlanHandler::getFullPlanList($nav->limitstart, $nav->limit, $subselect, $this->state->sort, $this->state->search); $gcolors = array(); foreach ($rows as $n => $row) { $query = 'SELECT count(*)' . ' FROM #__acctexp_subscr' . ' WHERE plan = ' . $row->id . ' AND (status = \'Active\' OR status = \'Trial\')'; $this->db->setQuery($query); $rows[$n]->usercount = $this->db->loadResult(); if ($this->db->getErrorNum()) { echo $this->db->stderr(); return false; } $query = 'SELECT count(*)' . ' FROM #__acctexp_subscr' . ' WHERE plan = ' . $row->id . ' AND (status = \'Expired\')'; $this->db->setQuery($query); $rows[$n]->expiredcount = $this->db->loadResult(); if ($this->db->getErrorNum()) { echo $this->db->stderr(); return false; } $query = 'SELECT group_id' . ' FROM #__acctexp_itemxgroup' . ' WHERE type = \'item\'' . ' AND item_id = \'' . $rows[$n]->id . '\''; $this->db->setQuery($query); $groups = xJ::getDBArray($this->db); $rows[$n]->groups = array(); foreach ($groups as $group) { if (empty($group)) { continue; } if (!isset($gcolors[$group])) { $gcolors[$group] = array(); $gcolors[$group]['color'] = ItemGroupHandler::groupColor($group); } $rows[$n]->groups[] = (object) array('id' => $group, 'color' => $gcolors[$group]['color']); } } $grouplist = ItemGroupHandler::getTree(); $glist = array(); $sel_groups = array(); $glist[] = JHTML::_('select.option', 0, '- - - - - -'); if (empty($this->state->filter->group)) { $sel_groups[] = JHTML::_('select.option', 0, '- - - - - -'); } foreach ($grouplist as $id => $glisti) { if (defined('JPATH_MANIFESTS')) { $glist[] = JHTML::_('select.option', $glisti[0], str_replace(' ', ' ', $glisti[1])); } else { $glist[] = JHTML::_('select.option', $glisti[0], $glisti[1]); } if (!empty($this->state->filter->group)) { if (in_array($glisti[0], $this->state->filter->group)) { $sel_groups[] = JHTML::_('select.option', $glisti[0], $glisti[1]); } } } $lists['filter_group'] = JHTML::_('select.genericlist', $glist, 'group[]', 'size="4" multiple="multiple"', 'value', 'text', $sel_groups); $totals = array(); $query = 'SELECT count(*)' . ' FROM #__acctexp_subscr' . ' WHERE (status = \'Active\' OR status = \'Trial\')' . (empty($subselect) ? '' : ' AND plan IN (' . implode(',', $subselect) . ')'); $this->db->setQuery($query); $totals['active'] = $this->db->loadResult(); if ($this->db->getErrorNum()) { echo $this->db->stderr(); return false; } $query = 'SELECT count(*)' . ' FROM #__acctexp_subscr' . ' WHERE (status = \'Expired\')' . (empty($subselect) ? '' : ' AND plan IN (' . implode(',', $subselect) . ')'); $this->db->setQuery($query); $totals['expired'] = $this->db->loadResult(); if ($this->db->getErrorNum()) { echo $this->db->stderr(); return false; } foreach ($rows as $rid => $row) { $rows[$rid]->link = 'index.php?option=com_acctexp&task=index&entity=Membership&plan=' . $row->id . '&groups[]=all'; $rows[$rid]->link_active = 'index.php?option=com_acctexp&task=index&entity=Membership&plan=' . $row->id . '&groups[]=active'; $rows[$rid]->link_expired = 'index.php?option=com_acctexp&task=index&entity=Membership&plan=' . $row->id . '&groups[]=expired'; if ($totals['expired']) { $rows[$rid]->expired_percentage = $row->expiredcount / ($totals['expired'] / 100); } else { $rows[$rid]->expired_percentage = 0; } $rows[$rid]->expired_inner = false; if ($rows[$rid]->expired_percentage > 45) { $rows[$rid]->expired_inner = true; } if ($totals['active']) { $rows[$rid]->active_percentage = $row->usercount / ($totals['active'] / 100); } else { $rows[$rid]->active_percentage = 0; } $rows[$rid]->active_inner = false; if ($rows[$rid]->active_percentage > 45) { $rows[$rid]->active_inner = true; } if ($totals['active'] + $totals['expired']) { $rows[$rid]->total_percentage = ($row->expiredcount + $row->usercount) / (($totals['active'] + $totals['expired']) / 100); } else { $rows[$rid]->total_percentage = 0; } $rows[$rid]->total_inner = false; if ($rows[$rid]->total_percentage > 20) { $rows[$rid]->total_inner = true; } if (!empty($row->desc)) { $rows[$rid]->desc = stripslashes(strip_tags($row->desc)); if (strlen($rows[$rid]->desc) > 50) { $rows[$rid]->desc = substr($rows[$rid]->desc, 0, 50) . ' ...'; } } } HTML_AcctExp::listSubscriptionPlans($rows, $this->state, $lists, $nav); }
public function exportSales() { $db = JFactory::getDBO(); $query = 'SELECT `id`' . ' FROM #__acctexp_log_history' . ' WHERE transaction_date >= \'' . $this->filter['date_start'] . '\'' . ' AND transaction_date <= \'' . $this->filter['date_end'] . '\'' . ' ORDER BY transaction_date ASC'; $db->setQuery($query); $entries = xJ::getDBArray($db); switch ($this->options['collate']) { default: case 'day': $collation = 'Y-m-d'; break; case 'week': $collation = 'Y-W'; break; case 'month': $collation = 'Y-m'; break; case 'year': $collation = 'Y'; break; } $collators = array(); switch ($this->options['breakdown']) { default: case 'plan': break; case 'group': $all_groups = ItemGroupHandler::getGroups(); $collators = array(); foreach ($all_groups as $gid) { $collators[$gid] = ItemGroupHandler::getChildren($gid, 'item'); } break; } $historylist = array(); foreach ($entries as $id) { $entry = new logHistory(); $entry->load($id); if (empty($entry->plan_id) || empty($entry->amount)) { continue; } if (!empty($this->filter['groupid'])) { if (empty($this->filter['planid'])) { $this->filter['planid'] = array(); } $children = ItemGroupHandler::getChildren($this->filter['groupid'], 'item'); if (!empty($children)) { $this->filter['planid'] = array_merge($this->filter['planid'], $children); $this->filter['planid'] = array_unique($this->filter['planid']); } } if (!empty($this->filter['planid'])) { if (!in_array($entry->plan_id, $this->filter['planid'])) { continue; } } if (!empty($this->filter['method'])) { if (!in_array($entry->proc_id, $this->filter['method'])) { continue; } } $refund = false; if (is_array($entry->response)) { $filter = array('new_case', 'subscr_signup', 'paymentreview', 'subscr_eot', 'subscr_failed', 'subscr_cancel', 'Pending', 'Denied'); $refund = false; foreach ($entry->response as $v) { if (in_array($v, $filter)) { continue 2; } elseif ($v == 'refund' || $v == 'Reversed' || $v == 'Refunded') { $refund = true; } } } $date = date($collation, strtotime($entry->transaction_date)); if ($this->options['breakdown'] == 'plan') { if (!array_key_exists($entry->plan_id, $collators)) { $collators[$entry->plan_id] = 0; } } if (!isset($historylist[$date])) { $historylist[$date] = array(); } $historylist[$date][] = $entry; } $line = array("line" => "Date"); if ($this->options['breakdown'] == 'plan') { foreach ($collators as $col => $colamount) { $line['plan-' . $col] = "Plan #{$col}: " . SubscriptionPlanHandler::planName($col); } } elseif ($this->options['breakdown'] == 'group') { foreach ($collators as $col => $colplans) { $line['group-' . $col] = "Group #{$col}:" . ItemGroupHandler::groupName($col); } } $line['total_sum'] = "Total"; // Remove whitespaces and newlines foreach ($line as $larrid => $larrval) { $line[$larrid] = trim($larrval); if (is_numeric($larrval)) { $line[$larrid] = AECToolbox::correctAmount($larrval); } } $this->exphandler->putDescription($line); $totalsum = 0; $collate_all = array(); foreach ($collators as $col => $colv) { $collate_all[$col] = 0; } foreach ($historylist as $date => $collater) { $linesum = 0; $collatex = array(); foreach ($collators as $col => $colv) { $collatex[$col] = 0; } foreach ($collater as $entry) { if ($this->options['breakdown'] == 'plan') { $collatex[$entry->plan_id] += $entry->amount; $collate_all[$entry->plan_id] += $entry->amount; $linesum += $entry->amount; $totalsum += $entry->amount; } else { $pgroup = 0; foreach ($collators as $gid => $gplans) { if ($entry->plan_id == $gid) { $pgroup = $gid; break; } } if ($pgroup) { $collatex[$pgroup] += $entry->amount; $collate_all[$pgroup] += $entry->amount; } $linesum += $entry->amount; $totalsum += $entry->amount; } } $line = array("date" => $date); foreach ($collators as $col => $colamount) { if ($this->options['breakdown'] == 'plan') { $line['plan-' . $col] = $collatex[$col]; } else { $line['group-' . $col] = $collatex[$col]; } } $line['total_sum'] = $linesum; // Remove whitespaces and newlines $i = 0; foreach ($line as $larrid => $larrval) { $line[$larrid] = trim($larrval); if (is_numeric($larrval) && $i) { $line[$larrid] = AECToolbox::correctAmount($larrval); } $i++; } $this->exphandler->putln($line); } $line = array("line" => "Grand Total"); foreach ($collate_all as $col => $colamount) { if ($this->options['breakdown'] == 'plan') { $line['plan-' . $col] = $colamount; } else { $line['group-' . $col] = $colamount; } } $line['total_sum'] = $totalsum; // Remove whitespaces and newlines foreach ($line as $larrid => $larrval) { $line[$larrid] = trim($larrval); if (is_numeric($larrval)) { $line[$larrid] = AECToolbox::correctAmount($larrval); } } $this->exphandler->putSum($line); }