/** * @param integer $id */ static function resolveTreeItem($id) { $tree = array(); $tree['id'] = $id; $tree['name'] = ItemGroupHandler::groupName($id); $groups = ItemGroupHandler::getChildren($id, 'group'); if (!empty($groups)) { // Has children, append them $tree['children'] = array(); foreach ($groups as $child_id) { $tree['children'][] = ItemGroupHandler::resolveTreeItem($child_id); } } return $tree; }
public function Action() { if (empty($_POST['start_date'])) { return null; } $db = JFactory::getDBO(); $start_timeframe = $_POST['start_date'] . ' 00:00:00'; if (empty($end)) { $end = date('Y-m-d', (int) gmdate('U')); } $end_timeframe = $end . ' 23:59:59'; $query = 'SELECT `id`' . ' FROM #__acctexp_log_history' . ' WHERE transaction_date >= \'' . $start_timeframe . '\'' . ' AND transaction_date <= \'' . $end_timeframe . '\'' . ' ORDER BY transaction_date ASC'; $db->setQuery($query); $entries = xJ::getDBArray($db); if (empty($entries)) { return "nothing to list"; } $historylist = array(); $groups = array(); foreach ($entries as $id) { $entry = new logHistory(); $entry->load($id); $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('Y-m-d', strtotime($entry->transaction_date)); $pgroups = ItemGroupHandler::parentGroups($entry->plan_id); if (!in_array($pgroups[0], $groups)) { $groups[] = $pgroups[0]; } if (!isset($historylist[$date])) { $historylist[$date] = array('amount' => null, 'groups' => null); } if ($refund) { $historylist[$date]['amount'] -= (double) $entry->amount; $historylist[$date]['groups'][$pgroups[0]]--; } else { $historylist[$date]['amount'] += (double) $entry->amount; $historylist[$date]['groups'][$pgroups[0]]++; } } foreach ($historylist as $date => $entry) { ksort($historylist[$date]['groups']); } $return = ""; $return .= '<table style="background-color: fff; width: 30%; margin: 0 auto; text-align: center !important; font-size: 180%;">'; $groupnames = array(); foreach ($groups as $group) { $groupnames[$group] = ItemGroupHandler::groupName($group); } $closer = 0; $incomplete = false; foreach ($historylist as $date => $history) { if (date('D', strtotime($date)) == 'Mon') { $week = array(); } elseif (!isset($week)) { $week = array(); $incomplete = true; } $return .= '<tr style="border-bottom: 2px solid #999 !important; height: 2em;">'; $return .= '<td title="Date" style="text-align: left !important; color: #aaa;">' . $date . '</td>'; $return .= '<td style="width: 5em;"> </td>'; foreach ($groups as $group) { if (empty($history['groups'][$group])) { $count = 0; } else { $count = $history['groups'][$group]; } $return .= '<td title="' . $groupnames[$group] . '" style="font-weight: bold; width: 5em;">' . $count . '</td>'; if (isset($week)) { $week['groups'][$group] += $count; } } if (isset($week)) { $week['amount'] += $history['amount']; } $return .= '<td style="width: 5em;"> </td>'; $return .= '<td title="Amount" style="text-align: right !important; color: #608919;">' . AECToolbox::correctAmount($history['amount']) . '</td>'; $return .= '</tr>'; $return .= '<tr style="height: 1px; background-color: #999;">'; $return .= '<td colspan="' . (count($groups) + 4) . '"></td>'; $return .= '</tr>'; $closer = 0; if (date('D', strtotime($date)) == 'Sun') { $return .= '<tr ' . ($incomplete ? 'title="Incomplete!"' : '') . 'style="border-bottom: 2px solid #999 !important; height: 2em; background-color: #ddd;">'; $return .= '<td style="text-align: left !important; color: #aaa;">' . ($incomplete ? '(Week)' : 'Week') . '</td>'; $return .= '<td style="width: 5em;"> </td>'; foreach ($groups as $group) { if (empty($week['groups'][$group])) { $count = 0; } else { $count = $week['groups'][$group]; } if ($incomplete) { $return .= '<td title="' . $groupnames[$group] . '" style="font-weight: bold; width: 5em;">(' . $count . ')</td>'; } else { $return .= '<td title="' . $groupnames[$group] . '" style="font-weight: bold; width: 5em;">' . $count . '</td>'; } } $return .= '<td style="width: 5em;"> </td>'; if ($incomplete) { $return .= '<td title="Amount" style="text-align: right !important; color: #608919;">(' . AECToolbox::correctAmount($week['amount']) . ')</td>'; } else { $return .= '<td title="Amount" style="text-align: right !important; color: #608919;">' . AECToolbox::correctAmount($week['amount']) . '</td>'; } $return .= '</tr>'; $return .= '<tr style="height: 1px; background-color: #999;">'; $return .= '<td colspan="' . (count($groups) + 4) . '"></td>'; $return .= '</tr>'; $closer = 1; $incomplete = false; } } if (!$closer) { $return .= '<tr style="border-bottom: 2px solid #999 !important; height: 2em; background-color: #ddd;">'; $return .= '<td title="Date" style="text-align: left !important; color: #aaa;">(Week)</td>'; $return .= '<td style="width: 5em;"> </td>'; foreach ($groups as $group) { if (empty($week['groups'][$group])) { $count = 0; } else { $count = $week['groups'][$group]; } $return .= '<td title="' . $groupnames[$group] . '" style="font-weight: bold; width: 5em;">' . $count . '</td>'; } $return .= '<td style="width: 5em;"> </td>'; $return .= '<td title="Amount" style="text-align: right !important; color: #608919;">' . AECToolbox::correctAmount($week['amount']) . '</td>'; $return .= '</tr>'; $return .= '<tr style="height: 1px; background-color: #999;">'; $return .= '<td colspan="' . (count($groups) + 4) . '"></td>'; $return .= '</tr>'; $closer = 1; } $return .= '</table><br /><br />'; return $return; }
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); }